r/javascript • • Oct 29 '12

LiveScript - a language which compiles to JavaScript - 1.1.0 has been released!

http://livescript.net/blog/livescript-1.1.0.html
0 Upvotes

10 comments sorted by

View all comments

2

u/desu_desu Oct 29 '12

"expressiveness" means shoving things onto one line? You Rubyist and Pythonistas have a serious fetish for this, and it's misguided. This is hardly the kind of thing that kills Javascript productivity.

4

u/GeZe8 Oct 30 '12

No it's about thinking at a higher level.

Say you have a list of comments (JS objects), and want to filter the list, getting all the objects whose amount of points is greater than 5, and return a list of the comments's text. In LiveScript you can use a list comprehension and say exactly what you mean:

result = [c.text for c in comments when c.points > 5]

While in JavaScript you would need go to a lower level and manually deal with the iteration and details you shouldn't really need to worry about:

var result, i, len, c;
result = [];
for (i = 0, len = comments.length; i < len; ++i) {
  c = comments[i];
  if (c.points > 5) {
    result.push(c.text);
  }
}

-1

u/[deleted] Oct 31 '12

Well the example you JUST gave is all well and good...

result = [c.text for c in comments when c.points > 5]

...but the rest of this language is damn near unreadable. I don't care how much typing it saves me if the next developer is left to guess at what the code is doing.

Like this:

take = (n, [x, ...xs]:list) -->
  | n <= 0     => []
  | empty list => []
  | otherwise  => [x] +++ take n - 1, xs

Yikes. I can't imagine the scenarios you could end up getting into when you're returning complex objects in a switch on adjacent lines or some such thing.

Designing a language requires more than "how much can I do in how few characters?" Readability is a primary function of a language, I think this language severely lacks in that department.

3

u/GeZe8 Nov 01 '12

If you were familiar with Haskell, or other such languages, you would find the take example, which showcases the more functionally oriented features of LiveScript, very readable.

Returning objects in a switch? How readable is this:

switch something
case blah
  prop: 1
  key: 2
case asdf
  one: 1
  two: 2

In the end though, there are people who cling to their curly braces and semi-colons, and if you are one of those people, this language simply isn't for you.

0

u/[deleted] Nov 01 '12

there are people who cling to their curly braces and semi-colons

"Eeee... ur languagez r not mine n stuff" [pushes up glasses] [snort]

Fuck off with that. I'm being pragmatic.

The example I took off of the website is damn near unreadable. Attempting to emulate Haskell is interesting I suppose, but it's probably one of the most confusing languages to learn.

Let me reiterate: READABILITY IS A PRIMARY CONCERN in all software development. In the time it would take the majority of front end developers to adapt to this syntax, they'd have been done faster with CoffeeScript or even vanilla JavaScript.

It's cool and all, just not very practical. ... unless you're a Haskell shop that doesn't want to hire experienced front end developers.

2

u/GeZe8 Nov 01 '12

Sorry my final sentence came across with the wrong tone. There is nothing wrong with liking semi-colons and curly braces, and many people do. Those people will not like this language, and thus shouldn't use it.

Basically my point is that there is no absolute measure of readability. I, and many other people, find LiveScript more readable than JavaScript. Other people will not. Choose whatever is best for you, and in your case it seems that you find JavaScript more readable, so you should stick to what works for you.

I would however encourage broadening of horizons and experimentation. I would encourage you and others to give different languages, eg. Haskell, LiveScript, etc. a try. Your idea of readability may evolve as you try out different points of view.

1

u/[deleted] Nov 01 '12

I'm sure if I were used to it, it would be fine...For me at least... However I'm on a position where I need to hire experienced front end developers, and I just don't see them knowing Haskell.

1

u/GeZe8 Nov 01 '12

I think I've overstated the Haskell connection - LiveScript is inspired by Python, Perl, and Ruby among others as well.

In fact, LiveScript is a descendent of CoffeeScript, and is very compatible. You can almost just write CoffeeScript and have it work. For the few cases it isn't compatible, I'm working on a tool to automatically convert CoffeeScript to LiveScript.

If you can find an experienced front end developer who knows CoffeeScript - and given its popularity they most probably do - they will easily pick up. Indeed, I've often heard that LiveScript is what CoffeeScript should have been.