Spot any errors? let me know, but Unleash your pedant politely please.

Sunday 22 February 2009

{ … }

I don't really like curly braces, but I appreciate this is a personal thing. I don't dislike them nearly as much as I used to. I do prefer a good solid beginend, but at least the braces are language independent ... that is if someone is programming in Italian, they work just as well.

What I really, really hate is this …

   if (x==y) {
      …
   }


simply because the block delimiters don't line up. A far better style is this…

   if (x==y)
   {
      …
   }


I've seen coding standards that do it the right way, but I don't recall ever seeing it written the right way in a coding book. People may argue the right way this wastes a line. Bollocks! For the sake of readbility, a bit of white space delineates blocks quite nicely. Where you don't need it is when the block is very short. For example, both

   if (fileIsOpen) {closeFile();}

and

   if (fileIsOpen)
      {closeFile();}


are fine.

Python doesn't have this problem. It's one of the main reasons I like it.

No comments:

Post a Comment