Live data from Hacker News

Of parser-fetishists and semi-colons

christianheilmann.com

11–20 of 125 posts

Re: Of parser-fetishists and semi-colons

#11
I've been shocked at the level of disrespect for language standards here. Yes: adding semicolons is probably good practice because it avoids the chance of stumbling over bugs like this. And yes: the ASI feature in Javascript is in hindsight a terrible mistake.

That said: you go to war with the language you have, not the one you might want or wish to have.

ECMAScript is ECMAScript. Arguing that your transformation tool doesn't need to handle a feature specified in the language and supported by all known implementations is just ridiculous. Arguing that people making use of a feature that the language standard says they can (and that works) are "sloppy" is equally dumb. Even weirder are the people who jumped on the use of the && operator to effect an "if" as "abuse" -- this is an idiom pervasive in lots of areas and (again) well-supported by Javascript.

Not everyone is going to have the same aesthetics, everyone has a different idea about what features are "fun" and which are "sloppy". And decades of experience in the "code convention hell" world of enterprise programming has taught us nothing if not that this sort of pedantry helps no one. If you want to use Javascript, you have to take the whole language -- warts and all.

Re: Of parser-fetishists and semi-colons

#12
post #3

I think the argument that we shouldn't rely on the parser for certain language features is a bit silly (including interpreting end-of-statements). The language is precisely what the parser says it is, and nothing more or less. JSMin is free to not do what the parser does of course, but that won't be Javascript.

Surely the language is precisely what the spec says it is?

"The parser is the spec" is a nasty design smell, IMO.

Re: Of parser-fetishists and semi-colons

#14
Add the semicolon

"but but but" add the semicolon

There's so much FOR it, it's unbelievable. Yes, it's good to 'break the rules' now and then. Add the semicolon

This is not about if JS allows it or not. It's important, but mostly irrelevant.

You can also not add 'var' to JS variables unless needed. That's going to be a lot of fun when it goes wrong.

But here are the million dollar questions:

1 - How much time is spent making it work without a semicolon as opposed to just typing it? This is not about typing ';' - time for that is irrelevant, but the mental effort of doing so 2 - How much time will it be wasted to fix minifiers (that is, add to them the intricacies of no-semi colon parsing and probably having to write a whole different parser) 3 - How much mental effort is needed to comprehend and correctly fix non semicolon code

Number 3 is the biggest issue and if you don't believe me it goes by another name: coding standard

Yes, JS works without semicolons. And yes, C works without indenting, without meaningful names to variables, etc.

It's not about "to write JS you should know all the nitty-gritty rules of the language and you're stupid if you don't know them so you just add semicolons". It's about teamwork, and facilitating code comprehension (and maintenance).

And language designers make mistakes. They don't know if a feature is going to become a trap, irrelevant to 99% of developers (and with an easy workaround) or just a pain in the behind.

Re: Of parser-fetishists and semi-colons

#15

Now, this could be easily solved – by adding the friggin semicolon. What this furore misses is that the original issue (JSMin failing to minify bootstrap-dropdown.js) was already fixed when the bug was raised [1]. Fixed without adding semicolons. Everyone should be happy with that. Developers of bootstrap got to stick to their "no semicolons" schtick, and the person with the original problem got it fixed. Everyone se…

That isn't really the original issue at all, Crockford's comment is just what brought it to a boilover. The lack of semi-colons has been brought up in issue after issue on the bootstrap project. Each time it's been rejected for the same arguably poor reasoning. Christian's post is completely spot on here. Javascript was designed to be tolerant of errors and inconsistencies as much as it could. That fact however, shou…

By "original issue", I was referring to the actual GitHub issue / bug report.

On the wider issue of semicolons I am in agreement of you, and all my own code is written with that in mind - though I respect the bootstrap authors preference and would style my pull requests without semicolons.

If their insistence on not using semicolons causes conflict with other popular software, I would hope they see sense and fix those conflicts - even if that meant adding a semicolon or two.

Re: Of parser-fetishists and semi-colons

#16
All the people arguing that the code as was presented should is good and right, I present this:

Everyone knows that debugging is twice as hard as writing a program in the first place. So if you are as clever as you can be when you write it, how will you ever debug it? ~Brian Kernighan

I couldn't tell that the second line in the code in question was an if statement at first without actually thinking about it. How is that helpful?

Re: Of parser-fetishists and semi-colons

#17

This whole debacle is the epitome of what I call alpha-nerd behavior, and it's slowly killing my interest in software development.

It's actually quite easy to develop software while being only vaguely aware of and emotionally uninvested in these sorts of kerfuffles.

Re: Of parser-fetishists and semi-colons

#18
post #13

Anyone else think this is by far the most boring technical debate ever to hit HN?

Agreed!

It amazes me how much time people have spent arguing over this.

When I see an open source library that's not coded in the way I like, I either customize it to my liking or look for alternatives.

The only time I would really care about someone's programming style is when I work with them, otherwise live and let live.

Re: Of parser-fetishists and semi-colons

#20
Haven't yet seen anyone point out what unpleasantly quirky code this was in the first place:

    !isActive && $parent.toggleClass('open')
It should have been written like this:

    if (!isActive) {
         $parent.toggleClass('open');
    }
What if somebody needs to add a second bit of code to be executed if isActive is false? In the first case, they'd have to refactor the code into an if statement before adding it. It should have been an if statement in the first place.

If you want something to happen if something is true, then you should use an if statement. This is not controversial stuff. Don't look for "clever" ways to misappropriate other parts of the syntax in order to appeal to your own personal minimalist aesthetic taste. Be cooperative.

Edit: On re-reading this it comes off as preachy. In fact I've very recently taken a closer look at some of my own "little quirks" and realised how unhelpful they were for other developers. I guess I'm embarrassed about that and want to spread the embarrassment around.

Post reply on HN