On Monday, 1 October 2012 at 15:26:20 UTC, Jonathan M Davis wrote:

I'm in the same boat. I've never had a problem with this, and it baffles me that
people keep thinking that it's an issue.

[SNIP]

- Jonathan M Davis


Nobody says it is an "issue". As you said, "To each their own": I know for a fact that I'm a sloppy coder, and I've run into the dangling if problem. It doesn happen often, but the frustration and wasted time, IMO, justifies the precautionary measures.

OP came stating he had the "same issue", ergo my recommendation. It is just a coding standard I follow, and it works for me. Other advantages (IMO) include making it slightly clearer what the body of the if is, and makes expanding the if easier on typing.

You are free to follow your own standard, but don't judge.

On Sunday, 30 September 2012 at 20:44:43 UTC, Andrej Mitrovic wrote:
On 9/30/12, monarch_dodra <[email protected]> wrote:
but when
that 1 liner becomes a 2 liner, it saves your life.

I can understand that. I typically don't add unnecessary braces unless I know I'll have to add a print statement in there for some debugging.
Of course here we enter the area of smart editors that could
automatically add braces if another statement was added. :]

This requires thinking. IMO when coding, thinking is a luxury that needs to be preserved for the real problem at hand, not how many curlies your code should contain. Besides, you never really know which ifs will contain that extra debug line. Especially, it is during furious debug sessions that you are most vulnerable to clumsy mistakes.

ALWAYS adding curlies might be "extreme", but it is a simple rule that is easy to follow, and has served me well.

Reply via email to