3 ms·
Since my http://eloquentjavascript.net http://eloquentjavascript.net recommends always terminating statements with semicolons, I guess I'm being directly addres
by marijn 16y ago
Since my http://eloquentjavascript.net http://eloquentjavascript.net recommends always terminating statements with semicolons, I guess I'm being directly addressed by this.
The suggestion that 'I don't understand semicolon insertion' doesn't really hit the mark. I wrote a JavaScript implementation.
Yet still I recommend everyone to use explicit semicolons. Going over the proposed style on this page, it all sounds pretty good, and semicolon insertion is starting to look okay. Until you realize that he wants you to start every line that starts with [(+/-,.* with a semicolon. This is needed to prevent semicolon insertion from failing you.
I'm sure one can get used to such a style, but it is completely 'out there', radically disconnected from JavaScript's C parentage, and, though that's a question of taste, ugly and irregular. This solution is worse than the problem, I think.
- quag 16y ago"Until you realize that he wants you to start every line that starts with [(+/-,.* with a semicolon." Good point, that isn't immediately clear. To help me understand, the article listed an example where a line started with a [, what are situations where a line is likely to start with (+/-,.* ?
- sharkbrainguy 16y agoThe immediate-function pattern starts with an open paren. (function () { }());
- Roboprog 16y agoSo you do this to nest temporary variables in another lexical scope inside of another outer function? (as vars have function scope rather than block scope) I'm not sure I would use this much, though now that you have pointed it out, I had better well be able to read it when somebody else does it to me. Thanks, I think.
- sharkbrainguy 16y agoMost javascript modules are defined inside a similar pattern, I'm surprised you haven't seen it yet. http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth http://www.adequatelygood.com/2010/3/JavaScript-Module-Patte... https://github.com/jquery/jquery/blob/master/src/ajax.js https://github.com/jquery/jquery/blob/master/src/ajax.js
- Roboprog 16y agoOdd. I've usually just returned or assigned the function def without the outer parens. For some reason, the outer parens syntax looked like it was defining an anonymous function, and also calling it immediately, which is of course not what that turns out to do. It's an interesting language, but I'm still at the dabbling stage. I'd like to think I'm past the voodoo stage (onfoo="whack()" attributes that call in-page functions with global variables), but maybe not.
- IsaacSchlueter 16y agoI don't mind you telling people to end lines with semicolons. I'd mind it if you told people that omitting semicolons causes cancer. (Or bugs.) -- EDIT: I just looked up your book to the point where you make this recommendation. You don't threaten any catastrophes, which is good. I disagree with the "complex and weird" conclusion, but it's certainly a valid decision to leave them out of the book if you'd rather not go into it. My opinion of you: Not Evil. <3
- Roboprog 16y agoFinally, somebody else who hates the largely gratuitous semicolons. Example: http://roboprogs.com/devel/2010.06.html http://roboprogs.com/devel/2010.06.html It's a shame they didn't just make it fully line oriented (like BASIC, xBASE, shell-script, Python, Ruby, ...), with the customary backslash or ampersand to indicate an incomplete line. (but they didn't) I guess then Netscape would have had to call it FooScript (or something silly like echhh-muh-script). The worst thing I hate about the "add semicolons!" religion is that it teaches people not to spot statements that are going to be terminated by a newline. So then, I have to see all the extra noise on each line :-( Don't people test the crap they write?!?