Hacker News new | ask | show | jobs
by szmarczak 90 days ago
> human only looking at the indentation and not realizing the braces don't match.

If it ever gets to that point, a refactor is obligatory.

Don't give the human tools to make easy mistakes. Any grammar can be abused, so blame the human for not writing clean code.

1 comments

Javascript's delimeter soup ((){([]{})}); can become near impossible to parse barebrained, especially when mixed with indents and semicolons.

Semicolons are just noise. They're absolutely redundant.

Some brackets are necessary, but whitespace/indent languages make it clear there's a lot of redundancy there too.

The goal is to minimise errors and cognitive load. The fewer characters the better.

> whitespace/indent languages make it clear there's a lot of redundancy there too.

The only purpose for whitespace indentation is to make the code easier on the eyes. A space shouldn't have an impact in terms of execution, that would be too hazardous. It's too easy to randomly insert a space rather than a character.

> It's too easy to randomly insert a space rather than a character.

What are you doing with your code? I never find myself just randomly inserting characters.

> I never find myself just randomly inserting characters.

Hasn't it ever occured to you trying to insert a space at your mouse but your cursor wasn't there? People sometimes forget to click (or think the cursor is already there), myself included. Characters are easier to spot because they are not invisible and random letters cause compile errors.

If it has never occurred to you, then good for you. However I do not see what the benefit of not using closing brackets would be.

I don’t use the mouse when editing code, so this particular mistake does not happen to me.

> I do not see what the benefit of not using closing brackets would be.

Less visual noise. And the ability to use braces for other syntax.

> I don’t use the mouse when editing code, so this particular mistake does not happen to me.

Fair point.

> Less visual noise.

It doesn't solve this problem of your eyes guessing the correct indentation, especially when using two spaces (I hate two spaces even with braces). You could set up your IDE so it highlights the block and prints a hint at the end what block is ending, however you lose this once you open a plain text editor.

The point of using braces for this is that you can count them.

Also, if you were to print the code without braces on a paper, it would be a hard time reading, since the paper is much smaller than a 27" monitor.

> And the ability to use braces for other syntax.

There's other ways. For example, {} in Swift can be also used for ResultBuilder. And if you need the braces without knowing the type upfront, you can prefix it e.g. ${}.