News for hackers. Stuff that matters.
Re:Effective JavaScript Reviewed by lhorie on Thursday January 03, 2013 @11:17AM (#5002990)
No offense but the idiom you talked about sounds like "clever code" (in the bad way). One shouldn't have to be guessing what a sequence of semicolons and parentheses are for. There are perfectly self-explanatory language constructs to deal w/ post-file-concatenation code integrity (e.g. "new function" is just one character longer, and if you really want to be explicit and/or pedantic, there's "void function() {}()", which is not that much longer.
Re:Effective JavaScript Reviewed by raganwald on Thursday January 03, 2013 @11:43AM (#5003147)
None taken!

As I pointed out, I was using this idiom out of superstition, I didn't fully understand what it did and why I was doing it. Now that I read The Fine Book, I'm in a better position to evaluate whether it is necessary and why other approaches may be superior.

I see that the review could be improved by explaining that the idiom is not something the book recommends pr se, but rather something I understood once I read the book.

Re:Effective JavaScript Reviewed by schmrz on Thursday January 03, 2013 @12:55PM (#5003545)
Correct me if I'm wrong but I believe that the straightforward option is that the tools that perform concatenation handle this as well. Are there any downsides to this approach?
Re:Effective JavaScript Reviewed by lhorie on Thursday January 03, 2013 @01:26PM (#5003724)
Technically speaking no, but socially speaking yes. You wouldn't want your code base made entirely out of code golfing that works through miraculous twists and bends. By the same logic, you should prefer even small aspects of your code to be clear to a junior developer (or even yourself a year from now), rather than overly clever and packed with several layers of obscure knowledge in a single character.
Re:Effective JavaScript Reviewed by schmrz on Friday January 04, 2013 @07:52AM (#5007372)
I completely agree, that's why I'm saying that it shouldn't be in the codebase. It should be handled by external tools that are performing the concatenation.

Of course that begs the question if this is necessary at all since I personally haven't seen it used but I haven't read the source of many JavaScript projects either.

Re:Effective JavaScript Reviewed by lhorie on Friday January 04, 2013 @10:10AM (#5007902)
I'm of the opinion that the behavior of code shouldn't be changing depending on what tool you pass it through. If down the road your homebrew concatenation script gets replaced by, say, a minification tool that does concats, but no ASI defensive code, then your code might break.

Besides, you don't necessarily want all files to be automatedly wrapped in a function. jQuery for example would break.

Re:Effective JavaScript Reviewed by gilini on Thursday January 03, 2013 @01:14PM (#5003647)
Creation of an empty statement and dissemination of "superstitious programming", as I like to call it.