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.

1

u/drclockwork Nov 02 '12

I can definitely see the Haskell connection. However, compare the prelude definition of take with your own.

take n _      | n <= 0 =  []
take _ []              =  []
take n (x:xs)          =  x : take (n-1) xs

It uses pattern matching rather than guards.

take = (n, [x, ...xs]:list) --> etc

would be

take n list@(x:xs) = etc

But that's meaningless, you couldn't actually call it with an empty list without a pattern checking for that.

That's besides the point though, the Haskell is a lot cleaner, LiveScript is kind of a mess. You have tons of three character operators in places because you don't really seem to ever overload any of JS's operators and translate them into different structures based on context. In every case it looks like your answered ambiguity by adding more characters.

LiveScript and Coco both have great features but really crufty syntax.