Quote:
Originally Posted by shamanNS
So, are you telling me that Lua (or whatever language's 'data structure' / collection/list/array type that code snippet represents) is different than almost any other language under the Sun (even CSS properties list! respect those same conventions) where any type of "enumerating stuff" shouldn't end with a comma as that results in syntax error or parsing error?
|
It's not a syntax error in Java (although it used to be at some point in now ancient implementations), JavaScript (unless you still need <=IE8), C#, Python, Ruby, Perl, PHP, etc. And of course it's not a syntax error in Lua either.
If I'm not mistaken, C89 and C++11 allow for it too. Why older C++ wouldn't… I have no idea.
Quote:
Originally Posted by pazos
We can argue that braces are not needed in this particular example, like the comma in your sample case.
|
Yup, I'm always annoyed when I come across if statements without curly braces. Not because they are necessary as written because obviously they're not right there and then, but because I have to go about adding braces first instead of just quickly adding whatever I want to add.
Besides avoiding some hopefully minor annoyance (although with curly braces you can get undetected wrong behavior), both curly braces and trailing commas have the diff issue, in that you get some useless noise in your diffs. Again not a big deal, but still a minor annoyance that's nicer to do without.
So:
1. Fewer unintended errors, whether benign (syntax) or harmful (behavior).
2. Cleaner diffs.
3. Less effort. You could see this as a restatement of 1 and 2, but not exactly. I think I'm fairly safe these days from harmful errors introduced by 1 (through bad experience!), but I'm still annoyed at the minor effort of having to add braces or commas. You could also sort the list alphabetically using your editor if desired without running into 1, so I think it's worth making it a separate point.
Therefore languages that don't allow for trailing commas slightly annoy me.
CSS is a bit different though, depending on the specifics. I'm not generally annoyed by it.
Quote:
Originally Posted by shamanNS
I personally hate people that are omitting curly braces for single statement if/else blocks just as much as I hate people that are omitting parentheses when assigning "arrow functions" that take only one argument to a variable or a constant (even though that particular case is mainly "just" offence in regards to code readability /glanceability
|
I think it's fine (for readability, anyway) if it's indented properly. To take the code from above:
Code:
if(something)
return true;
else
return false;
However, the problem now becomes that the indentation is misleading.
Code:
if(something)
bla;
// this is always executed
blabla;
In that sense the way Python works is nice, although mostly it annoys me. I really like being able to do something like:
Code:
if (something) {
indented();
quick_debug();
indented_orig();
}
I think that makes it easier to work with.
tl;dr I prefer Lua over Python in many ways even though they seem superficially similar, and this is one of them.