6 ms·
Minification has already been mentioned, but I wanted to re-iterate as it's such an important point. You can reduce size over the wire by as much as 30-80% by m
by sh1mmer 18y ago
Minification has already been mentioned, but I wanted to re-iterate as it's such an important point. You can reduce size over the wire by as much as 30-80% by minifying and obfuscating (something like YUI or Dojo compressors do this).
Not having semi-colons risks a lot of code breakage. Doug Crockford's JSMin has an aggressive mode which always strips line breaks and another which doesn't to avoid breakage when semicolons don't exist.
Personally I would just say that if you don't use semi-colons you should think hard about why you code at all. I'm not the anal-retentive type but sloppy code isn't awesome. I would put this in the same category as naming variables $whatever or $x. If you've never picked up someones second hand project you may not appreciate why a pleasant coding style matters.
- timknauf 18y agoI wasn't intending to come across as being anti-code-conventions! I love coding and I'm a bit shocked that my questions suggest to you that I might have a sloppy coding style in general. :^) I agree that conventions and shared idioms are extremely important. My question is, "why is this a convention?", not "why should we use conventions at all?". I'm all for adopting the semicolon convention myself, even in sole-programmer projects, if there are reasons for using it; that's basically why I asked the question in the first place. (And of course I adopt it if contributing to a project which already uses it - no need to rock the boat.) Things like minification are exactly what I'm interested in, although I was under the impression that HTTP compression does a better job than Javascript minifiers at solving the size problem. Obfuscation is, of course, another matter entirely.
- adelle 18y agoWelcome to the real world, where "the next programmer to work on this might be dumber than you" is considered a valid justification for cargo-cult programming. A good minifier should replace line-breaks with semicolons as appropriate using all the same inferencing rules as JavaScript itself. Until one of those comes along it seems like using semicolons is necessary to make the best use of the tools that do exist.
- timknauf 18y agoWelcome to the real world, where "the next programmer to work on this might be dumber than you" is considered a valid justification for cargo-cult programming. Yes, I am a little surprised that some of the responses have assumed that because I'm questioning the usefulness of a syntactic element, I'm not interested in code quality or consistency. Quite the reverse: I'm very interested in producing code that is as clean as possible. What I've been trying to discover is whether the semicolon is a vestigial element that can now be left behind. But the concensus seems to be that there is still a present need for semicolons, at least when it comes to interpreted JavaScript (though I'm still not convinced that the same holds for always-compiled variants like ActionScript). And like you say, current tools expect - quite reasonably - a certain coding style, even if they should use the full set of inferencing rules.
- inimino 18y agoI've written JavaScript sans semicolons for years and have not encountered incorrect parsing by any browser. I find this style cleaner and easier on the eyes. I haven't done any testing regarding parsing speed, but I would be shocked if anyone can demonstrate a measurable speed difference in a realistic testing scenario.
- timknauf 18y agoI've written JavaScript sans semicolons for years and have not encountered incorrect parsing by any browser. Yes, neither have I - but then I'm doing fairly simple stuff. I do test across a fairly broad range of browsers, though. I find this style cleaner and easier on the eyes. I'm glad I've found at least one kindred spirit in this regard! I was beginning to think I was the only one. I haven't done any testing regarding parsing speed, but I would be shocked if anyone can demonstrate a measurable speed difference in a realistic testing scenario. Perhaps with very, very large and complex code if the JavaScript engine uses an old-style interpreter? But surely the problem will continue to diminish away to nothing as more JavaScript engines implement efficient compilation.
- 18y ago
- adelle 18y agoA domain-specific compression algorithm will often outperform a general purpose compression algorithm, and sometimes a combination of both is even better. Besides, downloading a zip file is still faster than downloading the uncompressed file, so either everybody's doing HTTP compression wrong or it's not so hot to start with.