Live data from Hacker News

Why I sometimes hate JavaScript

geekregator.com

11–20 of 66 posts

Re: Why I sometimes hate JavaScript

#11
post #7

If you only hate Javascript sometimes, you are definitely new to the language. That said even in a proper language like Ruby this particular bug can happen, that's why communities around these languages strongly encourage proper discipline, enforced by tools. This bug most definitely should've made your tests go red, your linter give a warning and your code metrics suite should have a thing or two to about the huge e…

Is a function longer than 10 lines considered a problem by JavaScript analysis tools (or their users)? Surely you jest?

Re: Why I sometimes hate JavaScript

#12
post #11
post #7

If you only hate Javascript sometimes, you are definitely new to the language. That said even in a proper language like Ruby this particular bug can happen, that's why communities around these languages strongly encourage proper discipline, enforced by tools. This bug most definitely should've made your tests go red, your linter give a warning and your code metrics suite should have a thing or two to about the huge e…

Is a function longer than 10 lines considered a problem by JavaScript analysis tools (or their users)? Surely you jest?

No, by Ruby analysis tools like Rubocop. For my Javascript I use CoffeeScript, and I rarely go over 10 lines for a function. Javascript obviously is a bit weird in this because many Javascript programmers wrap whole prototypes in closures.

If your function is over 10 lines, it's probably bad, just look at your functions. Every 10+ line function I've ever written was only that long because of laziness and reducing them has always resulted in better legibility.

Re: Why I sometimes hate JavaScript

#14
Lots of comments here, and on the blog, essentially stating "It's not Javascript, it's that you forgot to [lint|test|format|.+]"

There are tools to make up for these language deficiencies, but our attitude to those bitten by the language deficiencies it's truly unfortunate.

Even Python, everyone's second favorite dead horse for dynamically typed language problems, would throw an error here.

Re: Why I sometimes hate JavaScript

#15
post #11
post #7

If you only hate Javascript sometimes, you are definitely new to the language. That said even in a proper language like Ruby this particular bug can happen, that's why communities around these languages strongly encourage proper discipline, enforced by tools. This bug most definitely should've made your tests go red, your linter give a warning and your code metrics suite should have a thing or two to about the huge e…

Is a function longer than 10 lines considered a problem by JavaScript analysis tools (or their users)? Surely you jest?

That's not a function longer than ten lines. That's a single expression longer than ten lines.

Re: Why I sometimes hate JavaScript

#16
The real issue here is it's not an error.

In another language the compiler/parser may have thrown a warning, but the issue here is actually that this is valid Javascript. Poorly composed Javascript, but completely valid.

Of course, jslint will complain about it (and a dozen other style things), so the more people utilize tools like that, the better.

More than anything, it's yet another reason to employ unit testing. Valid code that fails is very hard to debug without unit testing.

Re: Why I sometimes hate JavaScript

#17

What Node.js taught me is that JavaScript is language like any other. It has good parts, it has quirks and you have to know what are its strenghts and what are its weaknesses to use it properly. And you can say that about any other language.

Ehm, yes. Sorry to ask this, but what is your point? I don't understand why you are saying this thing, which nobody here would disagree with.

Does what you just said mean that we shouldn't talk about JS's weaknesses?

Or do you mean that we can, but that the points the author brings up have been beaten to death time and time again here on HN and this post + the inevitable comments it will attract have nothing to offer?

Those are the only two options I can think of for now. Or did you mean something else?

Re: Why I sometimes hate JavaScript

#18

What Node.js taught me is that JavaScript is language like any other. It has good parts, it has quirks and you have to know what are its strenghts and what are its weaknesses to use it properly. And you can say that about any other language.

Ehm, yes. Sorry to ask this, but what is your point? I don't understand why you are saying this thing, which nobody here would disagree with. Does what you just said mean that we shouldn't talk about JS's weaknesses? Or do you mean that we can, but that the points the author brings up have been beaten to death time and time again here on HN and this post + the inevitable comments it will attract have nothing to offer…

As I mentioned in another comment, whether this is inherently a weakness is up for debate. Valid code that fails can happen in any language. The problem here is Javascript can be very, very forgiving, which allows one to make mistakes like this.

There are many totally lucid, on-point criticisms of Javascript and at least once a day the language ticks me off, but this one is not so black-and-white.

Re: Why I sometimes hate JavaScript

#19
post #16

The real issue here is it's not an error. In another language the compiler/parser may have thrown a warning, but the issue here is actually that this is valid Javascript. Poorly composed Javascript, but completely valid. Of course, jslint will complain about it (and a dozen other style things), so the more people utilize tools like that, the better. More than anything, it's yet another reason to employ unit testing.…

Having JSLint and a test framework in my toolchain when developing with JS is so essential...it's like trying to write Ruby without using unit tests.
Post reply on HN