Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, sorry, omitting parentheses (because they're optional) can be "too clever". I love optional parentheses, but I feel like a lot of people omit them because they feel that they're supposed to, at the cost of code clarity. I'm arguing that you should omit them when doing so doesn't make the code ambiguous, but if you ever need them to improve code clarity, that you should use them.

The OP had a fine example of "doing it wrong", with the nested inner function call without parentheses. While technically valid, it's bad code because it's difficult to read, even for someone accustomed to optional parentheses. Such a construct is "clever" when it shouldn't be.



But then you have to think everytime whether you should put parantheses there or not. Is the code readable without parantheses? Should I put them there in case someone reads the code in a year and doesn't know about the problem domain ... ? It is not much, but it is extra cognitive load that is wasted.

It's akin to programming C and everytime you write a function, if statement or for loop you have to ponder whether it looks best to put the opening brace below the line or at the end of it. I hate reading code with an inconsistent brace placement style like that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: