inimino
inimino.org/~inimino · Personal blog · on HN since 2009
inimino is a programmer who writes about JavaScript, parsers, text editors, hiring senior engineers, and ending captchas.
What HN saysCommenters call his JavaScript semicolon article the best they have read on the subject and cite it on automatic semicolon insertion edge cases.
17HN people shared it
11linked it in comments
9stories submitted
85story points
6 years agolast shared
2009people per year2026
Most-shared posts
- 1Javascript and semicolon insertion13 people · 35 points · first shared 2010 · 12 comments on HN
- 2On Hiring Senior Engineers2 people · 8 points · first shared 2018 · 2 comments on HN
- 3ActiveShell: A Shell for the Web1 people · 39 points · first shared 2012 · 10 comments on HN
- 4What I require of a text editor.1 people · 2 points · first shared 2009 · discussion on HN
- 5Show HN: Using ActiveShell (Web shell) to solve ai-class puzzle1 people · 1 points · first shared 2012 · discussion on HN
- 6Logs 200905101 people · first shared 2009
- 7Peg first release1 people · first shared 2010
- 8Kill captcha1 people · first shared 2019
What HN people wrote when they linked it
feross · 2016-04-28
I recommend reading the following articles before you assume that omitting semicolons is dangerous.
An Open Letter to JavaScript Leaders Regarding Semicolons
http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leader…
JavaScript Semicolon Insertion – Everything you need to know
http://inimino.org/~inimino/blog/javascript_semicolons
Are Semicolons Necessary in JavaScript?
https://www.youtube.com/watch?v=gsfbh17Ax9I
Spreading FUD doesn't help anyone out.
ufo · 2013-02-23
I would just like to point out that people tend to blow the semicolon insertion thing out of proportion. For braces it really only comes up when returning object literals and for other things there are just a couple of features that can bite you (starting lines with parenthesis or array literals and so on)
http://inimino.org/~inimino/blog/javascript_semicolons
Sure, its best to always explicitly use semicolons but its not as dangerous to forget them as most make it sound.
einaregilsson · 2011-08-07
Ahem, maybe not as clear as I thought, since I found a few other edge cases I didn't know of in this excellent article:
Best article I've read on the subject: http://inimino.org/~inimino/blog/javascript_semicolons
KlausTrainer · 2010-07-26
> For me it's a 'yes' based on the simple rule that explicit is always better than implicit. That sort of 'optimisation' seems to be really cool when you're just starting out in a language but in the long run it isn't worth it.
I don't really get what you call implicit when you terminate statements with semicolons instead of linebreaks...
... Ok, I get what you're hinting it: there are some (very) few exceptions. However, I cannot see where there is any 'optimisation' in using linebreaks instead of semicolons. You better need to explain why someone should use both linebreaks _and_ semicolons, when only using linebreaks is actually as good as well.
Basically, it's just a matter of style. Aside from a few exceptions (e.g. described in http://inimino.org/~inimino/blog/javascript_semicolons), linebreaks terminate a statement. If you stick with writing only one statement per line, I don't see what's so implicit with it. Rather terminating a statement both with a line break and a semicolon is a tautology, and hence introduces unnecessary redundancy.
The actual question is, whether one can require that developers know the (maybe a handful) exceptions where a line break doesn't terminate a statement. I have decided (for myself) that I can require that knowledge, as it really comes down to only a few exceptions (that I believe are easy to remember).
But, of course, I'm aware that one can also come do another reasonable conclusion.
The only important thing is that people make a…
inimino · 2019-08-05
I wrote about another technique at the end of my own captcha rant:
https://inimino.org/~inimino/blog/kill_captcha
The proposed solution would replace captcha entirely, but to my knowledge nobody has tried it.
BrendanEich · 2015-03-05
See http://inimino.org/~inimino/blog/javascript_semicolons, hope it helps. The minimal semicolon style has only a few rules and many people find it easier to use and remember. I've used it but my C hacker habits go against it. It's a fine style.
/be
jemfinch · 2011-03-31
I hate automatic semicolon insertion. They complicate the language. Here's the rule for a language that uses semicolons to terminate statements:
1. Semicolons terminate statements.
Look at the rules for Go semicolon usage[1] or Javascript semicolon usage[2] or Python newline usage[3]. They're not simple. Entire essays can be and have been written describing the complexity introduced by saving programmers that single keystroke.
Maybe I'm crazy, but I want my tools to be simple. I would much rather type a thousand extra semicolons than spend extra hours internalizing the statement termination rules of the languages I use.
[1] http://groups.google.com/group/golang-nuts/browse_thread/thread/5ee32b…
[2] http://inimino.org/~inimino/blog/javascript_semicolons
[3] http://docs.python.org/reference/lexical_analysis.html
grayrest · 2010-03-17
There are a couple other parser generators for JS:
* http://zaa.ch/2k - Jison
* http://inimino.org/~inimino/blog/peg_first_release - another Packrat (has an es5 parser as an example)
Plus a few more that work but produce generated code that's too slow to be useful.
nixme · 2009-05-14
The google group is still active: http://groups.google.com/group/hacker-news-reads-sicp
Next meeting is on May 24, covering the end of chapter 2, exercises 2.73 - 2.97.
Here's the log from the last meeting: http://inimino.org/~inimino/projects/2009/SICP/logs/20090510
chad_walters · 2012-04-15
I have never written a line of JS in my life, which hopefully qualifies me as an unbiased outsider, but I don't agree that that Crockford's position here on JSMin is the right thing to do.
Here is what I see:
@fat is not inserting "!" needlessly as a statement separator. The "!" is there for its proper purpose, as a "unary not" operation, which will short circuit the second operand of the "&&" when isActive is false.
Given that, @fat has left out a semicolon in a way that is perfectly legitimate based on this language specification, at least as described in the 5.1 version linked from here: http://inimino.org/~inimino/blog/javascript_semicolons).
Could @fat have written the code differently so that he would have been required to include the ";"? Perhaps -- but I don't see why that counterfactual has any particular bearing here.
Crockford's own page on JSMin <http://www.crockford.com/javascript/jsmin.html> claims: "JSMin is a filter that omits or modifies some characters. This does not change the behavior of the program that it is minifying."
The fact is that @fat's code is legal code and JSMin is breaking it.
IMHO, Crockford is ignoring the technical matters at hand. @fat cannot be faulted for writing code that complies with the specification and for having a reasonable expectation that code minimizers will preserve the semantics of his legal code. Crockford (and others) may wish that the language specification did not include automatic semicolon insertion because it…