5 ms·
Yes, please! This applies to many other lists as well, not only restricted to JSON. Besides, imagine a world of Java, Javascript, C-like anything, where you wo
by megapatch 9y ago
Yes, please! This applies to many other lists as well, not only restricted to JSON.
Besides, imagine a world of Java, Javascript, C-like anything, where you would be DISALLOWED to have a semicolon after the last statement in a block. Crazy thought, right?
- webkike 9y agoIn C you couldn't follow cases and labels with just a semicolon, it was an invalid statement. That's because a statement couldn't be just a semicolon. But yes, I agree.
- deleted 9y ago[deleted]
- kijin 9y agoJavascript: automatically inserts semicolons for you at the end of a line, but doesn't allow commas at the end of a list.
- DelTaco 9y agoJavaScript does allow commas at the end of a list! :) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- kayamon 9y agoWelcome to Pascal.
- clouddrover 9y agoHow do you mean? In Pascal the semicolon after the last statement of a block is optional. So, for example, this: function square(const x : Integer) : Integer; begin result := x * x; end; Is equivalent to: function square(const x : Integer) : Integer; begin result := x * x end; If you mean in if-then-else constructions, then yes the semicolon must be at the end of the statement: if (condition) then dosomething else dosomethingelse;
- sillysaurus3 9y agoCommas are unnecessary. There is zero benefit to having them. The code is actually easier to parse if you just remove them from the rules list entirely. No commas might look weird for a day or so, but you quickly get used to it. (I'm ignoring the comma operator, which is a special case and not relevant to the main point.)
- mjevans 9y agoThey exist because of string concatenation. In some languages any consecutive strings are implicitly concatenated so that you can have a very long string split across many lines.
- deleted 9y ago[deleted]
- sjrd 9y agofoo(x, -y) is not the same as foo(x -y) (from your last sentence, I assume you were talking about JS in general, not just JSON)
- sillysaurus3 9y agoMm, fair point. Infix math rears its ugly head again. I've been living in Lisp a bit too long. Never mind. Actually, let's double down: Instead of writing 1+2, you should really be writing +(1 2). Don't you see how much easier that would make things? A single, uniform syntax everywhere! + is just a function that gets called like anything else! Your foo(x -y) example would become foo(x -(y)). I'm mostly joking.
- dasmoth 9y agoHaskell makes a reasonable job of combining infix operators with no commas between function arguments[1]. You sometimes end up with a few extra parentheses and $s instead, but things generally seem to work out. Does use commas for lists and tuples, though. The latter kind-of make sense, it's the commas that identify the expression as a tuple. Not sure what the rationale for commas in lists is, though. [1] Slightly complicated by currying (arguably, it's several successive function applications rather than one multi-arg application) but the end result is the same...
- emmab 9y agoIn Rust, omitting the last semicolon in a block indicates an implicit return of the final expression of the block.
- tomp 9y agoThat's terrible, to have semantics depend on such a tiny syntax change that's so easy to miss.
- tankenmate 9y agoI wish there was times that HN supported Quadratic Voting[0] so that I could more (but costly) up votes to a really sane and pertinent comment. [0] http://ericposner.com/quadratic-voting/ http://ericposner.com/quadratic-voting/
- alansammarone 9y agoI've never heard about quadratic voting before. This is very interesting!
- TheSpiceIsLife 9y agoThanks for the link, I started reading the paper. I love this: Groups frequently make collective decisions through majority rule. Legislators pass bills by majority; shareholders make most corporate decisions by (share-weighted) majority rule, as do directors; clubs, university faculties, and civic associations typically use majority rule as well. The reason that they do so is not entirely clear. (Emphasis mine).
- coldtea 9y ago>The reason that they do so is not entirely clear. Not clear? It's almost too clear as to be tautological. They do because they (a) think all members should have equal say, (b) most members in the group want X to be done. Unless we're talking about submitting to force or listening to expertise, why would many people wanting to do something, let fewer people tell them what to do instead? Heck, if it comes to fighting for what's to be done (the most effective but primitive form of getting a decision), the majority could beat up the minority and have its way anyway.
- quicklime 9y agoSome JavaScript style standards require no semicolons at the end of lines: https://standardjs.com/rules.html#semicolons https://standardjs.com/rules.html#semicolons
- darawk 9y agoYes, but he means no semicolon only on the last statement of a function, I believe.
- kakarot 9y agoI made the switch earlier this year and I don't think I would ever willingly go back. It just looks so much more parsable. Semicolons at the end of my statements just look ugly and savage now.
- masklinn 9y agoIn Erlang, commas and semicolons are separators not terminators. So you are in fact disallowed to have a semicolon at the end of a sequence of clauses, it's either nothing (for case) or a period (for functions)
- donatj 9y agoIt sounds dumb, but this was actually one of the things that turned me off Erlang despite my interest.
- masklinn 9y agoIt's definitely weird, but it allows for neat stuff e.g. in Emacs' erlang-mode when you type a semicolon it automatically creates a new clause (function or case) for you.