Live data from Hacker News

For modern development Javascript indeed is a shit language

live.julik.nl

61–70 of 243 posts

Re: For modern development Javascript indeed is a shit language

#61
post #7

Earlier quoted context omitted.

How do you handle Javascript ignoring wrong numbers of function arguments? Do you use a linter to catch this sort of thing? This part of Javascript sounds the most absolutely insane to me: Silencing an error like that is catastrophic.

Silencing an error like that is catastrophic. Silencing an error would be a problem, but in JS, it's not an error , because there's no concept of "wrong numbers of function arguments" built into the language. That's not to say you can't inspect the number of arguments yourself and throw an error, if some situation warrants it. But you don't have to do this. It's a very flexible, dynamic language. In some ways this fl…

It's still a programmer error when they accidentally call a function with 2 arguments when they meant to call it with 3. The fact that the language can't inform them of the error doesn't change that.

Re: For modern development Javascript indeed is a shit language

#62

Despite most of the points in this post being debatable — there's one bit that caught my eye: "Being nice will not help it, and CoffeeScript is not radical enough." As the guy who started CoffeeScript, I agree. It's an intentionally very conservative approach. But there's more than one good way to skin the JavaScript cat. I think it would be fun to take another run at the same problem — attempt to find a minimal, rea…

"but to do so with a much more radical design."

Now this is interesting. Working on anything!

Re: For modern development Javascript indeed is a shit language

#63

Earlier quoted context omitted.

It's not the only option in the browser.

What are other runtime options? - Flash? That's almost the same as JavaScript and it's getting obsolete. - Java? No one enables it on the client, thanks to security problems. - Asm.js/LLVM? These are immature and can't be used for production.

- GWT - Dart - ClojureScript

Re: For modern development Javascript indeed is a shit language

#64

Earlier quoted context omitted.

> [1,10,5,-15,-2,4].sort(function(a,b) {return a > b}) [ -15, -2, 1, 4, 5, 10 ] > [1,10,5,-15,-2,4].sort(function(a,b) {return ""+a > ""+b}) [ -15, -2, 1, 10, 4, 5 ] Perhaps .sort was initially designed to do something else, like sorting strings, rather than integers.

I'm pretty sure that the parent comment's author is aware of this. It does not change the fact that it's broken.

Why? Sorting strings is a far more common thing to do than just sorting numbers, so it makes sense to use simple string comparisons as the default algorithm. Rather than come up with something that first evaluates the types in the list and then tries to figure out what to do.

Re: For modern development Javascript indeed is a shit language

#65

Despite most of the points in this post being debatable — there's one bit that caught my eye: "Being nice will not help it, and CoffeeScript is not radical enough." As the guy who started CoffeeScript, I agree. It's an intentionally very conservative approach. But there's more than one good way to skin the JavaScript cat. I think it would be fun to take another run at the same problem — attempt to find a minimal, rea…

> I've been playing around with it a bit...

Tell us more!

Re: For modern development Javascript indeed is a shit language

#66

Despite most of the points in this post being debatable — there's one bit that caught my eye: "Being nice will not help it, and CoffeeScript is not radical enough." As the guy who started CoffeeScript, I agree. It's an intentionally very conservative approach. But there's more than one good way to skin the JavaScript cat. I think it would be fun to take another run at the same problem — attempt to find a minimal, rea…

> I think it would be fun to take another run at the same problem — attempt to find a minimal, readable, and easier-to-learn language that fits in the same role as JavaScript — but to do so with a much more radical design.

Do you think ClojureScript could fit this category? We have teams that use it in production without any significant problems at all.

Re: For modern development Javascript indeed is a shit language

#67
post #7

Personally, I disagree. I find JavaScript to be the most "write-able" language, and switching to Node + frontend JS as my main language (I've done Python, Ruby, PHP, Java and C++ as jobs) has been the best thing I've done in a long time. Express and Angular are amazing. Sure, it has a bunch of quirks. Sure, it's not good for everything (I do mostly relatively simple CRUD apps). Sure, in the browser, it gets slow when…

How do you handle Javascript ignoring wrong numbers of function arguments? Do you use a linter to catch this sort of thing? This part of Javascript sounds the most absolutely insane to me: Silencing an error like that is catastrophic.

In JS, sending the "wrong" number of arguments is frequently a feature. There's no concept of language-level function overloading, and it allows for the authorship of functions that take a variable or unbounded number of arguments (useful when coding in a functional paradigm).

Re: For modern development Javascript indeed is a shit language

#68
post #49

Earlier quoted context omitted.

The correct answer is it has to do with weak types. > `If compareFunction is not supplied, elements are sorted by converting them to strings and comparing strings in lexicographic` period end of the story. As I said explaining the historical context or labeling the brokennes with something like "weak typing" doesn't excuse. It still stays broken. > You might argue it's a shitty default, but please argue against reali…

> The correct answer is it has to do with weak types. No, it does not. You could define the exact same default function in Java, Haskell (requiring that the sorted type be a Show instance) or Python (hell, getting the exact same behavior in Python could hardly be simpler: `ar.sort(key=str)`. There, I broke it. That is near literally how the ECMAScript spec very explicitly defines the default comparison function. The…

> No, it does not. You could define the exact same default function in Java, Haskell (requiring that the sorted type be a Show instance) or Python (hell, getting the exact same behavior in Python could hardly be simpler: `ar.sort(key=str)`

I don't use JavaScript but to me this looks like a really broken implementation over weak typing. Of course, this isn't a trait of the typing system per se as it is a trait of the "interface", if you will, that it offers to the programmer.

What OP was probably annoyed by was the typical excuse the JS community offers for this behaviour: "it's weakly-typed so you can treat the arguments as anything you want". This misses the point of having a weak typing system: instead of using it to infer the type of the arguments and get a sane default comparison function, avoiding the verbosity typical of strongly-typed languages (where you have to specify the comparison function with the correct type signature), you have to specify the comparison function for anything that isn't a string. Bummer :-(.

I hope I haven't missed anything here; as I said, I'm not quite fluent in JavaScript.

Re: For modern development Javascript indeed is a shit language

#69

Despite most of the points in this post being debatable — there's one bit that caught my eye: "Being nice will not help it, and CoffeeScript is not radical enough." As the guy who started CoffeeScript, I agree. It's an intentionally very conservative approach. But there's more than one good way to skin the JavaScript cat. I think it would be fun to take another run at the same problem — attempt to find a minimal, rea…

CoffeeScript was obviously inspired by Ruby. While CS is great, I've never gotten over the usage of "->" or "=>" to signify a function. To me, Ruby's "def" or "do" reads so much better. Especially with "end", to signify a barrier, as opposed to whitespace. Have you considered porting Ruby directly to JavaScript?

By the way, thanks for your work on _ & Backbone!

Re: For modern development Javascript indeed is a shit language

#70
post #49

Earlier quoted context omitted.

The correct answer is it has to do with weak types. > `If compareFunction is not supplied, elements are sorted by converting them to strings and comparing strings in lexicographic` period end of the story. As I said explaining the historical context or labeling the brokennes with something like "weak typing" doesn't excuse. It still stays broken. > You might argue it's a shitty default, but please argue against reali…

> The correct answer is it has to do with weak types. No, it does not. You could define the exact same default function in Java, Haskell (requiring that the sorted type be a Show instance) or Python (hell, getting the exact same behavior in Python could hardly be simpler: `ar.sort(key=str)`. There, I broke it. That is near literally how the ECMAScript spec very explicitly defines the default comparison function. The…

> That might well be, but the default sort comparison function is not a demonstration of it.

Yes it is. It demonstrates weak typing which I also think is broken. If I wanted to sort a string, I would have done this:

      > ["1","2","3"].sort()
> (hell, getting the exact same behavior in Python could hardly be simpler: `ar.sort(key=str)`. There, I broke it.

You broke it by writing more code. That's good. Javascript is broken __unless__ you write additional code. That's the crux of the matter.

Post reply on HN