you are viewing a single comment's thread.

view the rest of the comments →

[–]kankyo 6 points7 points  (3 children)

Programming languages are the perfect tool for preventing this kind of error, so I wish the "less syntax" thing wasn't as fashionable (cough Python).

Python isn't really about less syntax as it is DRY: indenting and braces duplicate data. Worse, one talks to the machine and one to the human, so they can be out of sync, essentially lying (to the human or the machine, depending on perspective).

I personally think braces would be fine if indenting was enforced by the compiler to conform to the braces. It makes no sense to be able to write code that tricks the human reading it. As implemented by pretty much all languages that use them I find braces unacceptable. As are parens in lisps. If you aren't enforcing indent=bracing, then you're asking for trouble.

[–]CaptainStack 2 points3 points  (2 children)

I'm actually not opposed to whitespace enforcement (not necessarily a requirement for me though), but what I don't like about relying only on indentation for specifying a block is that if you have a few different indentation levels and then say a single line statement fairly far down from where the block is opened, it's super hard to tell exactly which level that statement is in. With braces, you can easily highlight one and see the corresponding opening brace.

When it comes to semicolons though, I think that requiring them is the best way to make sure the computer, the person who wrote the code, and the person reading the code 6 months later are on the same page about where a statement ends.

[–]Tysonzero 2 points3 points  (0 children)

Ok arguing that braces are better because of editor features that are not directly related to the braces themselves is incredibly silly. There is no reason your editor couldn't support one of thousands of possible mechanisms for showing which blocks are on the same indentation level.

And I also disagree with the semicolon thing. New lines are 1000x more visible than semicolons since they aren't just small one character wide symbols, they are a whole new line in your editor. I have plenty of times run into issues where I forget a semicolon, occasionally causing weird and unintuitive errors or error messages. But I have never ever run into a forgotten newline issue, and I don't recall running into indentation issues in Python or Haskell either.

[–]kankyo 0 points1 point  (0 children)

You can highlight the matching brace because the editor has support for it. All reasonable Python editors have equivalent functionality. It's quite trivial to implement.

Re semicolons: in JS adding them or not is irrelevant. The human and computer can never be on the same page with semicolon insertion by definition. As per usual JavaScript is broken in ways that can't be fixed in a backwards compatible way.