26 ms·
Why the hell people are refusing to use semicolons? I don't get it
by felipe_csl 14y ago
Why the hell people are refusing to use semicolons? I don't get it
- smhinsey 14y agoI'm sure there is a whole huge debate here that I'm unaware of, but it seems like a largely aesthetic choice to me, and on that basis, I find it really jarring as someone who is not an everyday JS author.
- Groxx 14y agoI've seen a few reasons. The main ones I encounter are: raising the skill requirement to contribute (you have to know JS better than average to never use a semicolon, and do so correctly), aesthetic (fewer characters looks better), and minimalism (don't use what you don't need).
- ricardobeat 14y agoMissed the most important: no more errors from missing semi-colons.
- rpearl 14y ago> raising the skill level to contribute That's insane. Good programmers need not know stupid tiny nits about Javascript (heck, I've worked on a Javascript JIT and I don't really know Javascript). That does not mean that they are not skilled. > aesthetic I don't understand how "you must carefully understand how the language parses to understand this line of code" is aesthetically pleasing when compared to unambiguity. > minimalism Here, it is needed, at least arguably (by douglascrawford). You could argue that the "optional semicolons" rule is ugly and not minimalistic, and thus the minimalistic approach would be to not use that rule.
- ricardobeat 14y agoSure the "raising the skill level" bit is just trolling. Omitting semi-colons is about removing ambiguity, and making it easier to spot inconsistencies. As a bonus, code looks cleaner. In this case, the minifier is breaking the code, regardless.
- fusiongyro 14y agoCan you parse this expression without parentheses? a && b && c || d || e + f > g && h The parser sure can. Do you have all the operator precedences memorized, or do you use superfluous parentheses because you're not always sure? It's true that the semicolon is not needed, and it's true that the minifier is breaking code. It may even be true that Crockford should fix it. But that doesn't change the fact that the omit-the-semicolons position is absurdly immature hipster posturing that serves no engineering purpose.
- deleted 14y ago[deleted]
- rtomayko 14y agoDo you use parenthesis to denote order of operations in all cases, even when extremely obvious? If not, should we assume your position is absurdly immature hipster posturing that serves no engineering purpose?
- jhuni 14y agoI use Lisp, so the answer to your question is yes. I do use parenthesis in all cases.
- atdt 14y agoraising the skill requirement to contribute (you have to know JS better than average to never use a semicolon, and do so correctly) Great idea! I propose some additional strategies for pruning the contributor pool: - All numbers in hexadecimal (every idiot knows decimal!) - No strict equality tests (too easy to reason about & uses extra character!) - Variable names must consist entirely of unicode ideographs (even my grandmother knows ASCII!) That should keep the idiots at bay!
- deleted 14y ago[deleted]
- manojlds 14y ago> raising the skill requirement to contribute (you have to know JS better than average to never use a semicolon, and do so correctly) Any fool can write code that a computer can understand. Good programmers write code that humans can understand. ~Martin Fowler
- tikhonj 14y agoSame reason people don't use semi-colons in Python, I imagine. Besides, I'm not willing to acknowledge any reasons for using semi-colons as significant. And without any significant reasons for it, I may as well not use them. Besides, it makes the code prettier :).
- kennywinker 14y agoI always think of using semicolons like using parentheses when doing math in code. It makes the order of operations explicit rather than implied. For example, 1 + 2 * 3 Solves to 7, obviously. But I'll write it in code like this: 1 + (2 * 3) Just to make it clear that I know what I mean, and I mean do the operations in _this_ order. Similarly, using semicolons to end lines means I am saying loud and clear... this line of code ends HERE. Obviousness is a good thing, no?
- ricardobeat 14y agoSo in this case: var value = x + fn (y).burp() Is it obvious that there is a missing semi-colon at the end of line 1? The code is technically correct without it (not that I approve of it). You can assume it's wrong, but it's just a guess. If your code is in no-semi-colon style, there is no ambiguity, you can be 100% sure that this is a mistake: there always should be a semi-colon guarding that parenthesis, regardless of intent: var value = x + fn ;(y).burp() It's about removing ambiguity and visual clutter with a simple set of rules. How many JS programmers know the difference between a function expression or declaration, and the semi-colon that should follow or not? You're dependent on a linter. Following the no-semi-colon rules makes your intentions clear in every case, without machine validation.
- mquander 14y agoI don't follow this argument. Putting a semicolon at the end of every statement, regardless of what follows, seems to be an even easier way to avoid making this bug.
- deleted 14y ago