www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/06/15/21:07:41

Date: Thu, 15 Jun 1995 20:02:23 -0400
From: dj (DJ Delorie)
To: junaid AT barney DOT eng DOT monash DOT edu DOT au
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: CODING STANDARDS: A GUIDE

> 2. Conditionals
> 
> 	if (condition) {
> 		...
> 	}
> 
> 	if (condition1 || condition2) {
> 	} else {
> 	}
> 
> 	if (foo && !bar) {
> 	} else if (bletch) {
> 	}

This syntax really bugs me and makes it harder for me to read the
code.  I prefer this way:


	if (condition)
	{
	  ...
	}

	if (condition1 || condition2)
	{
	  ...
	}
	else
	{
	  ...
	}

	if (foo && !bar)
	{
	  ...
	}
	else if (bletch)
	{
	  ...
	}

The rule being that matching braces are always in the same column, and
nothing else is ever on the line with them.  This makes it easier to
find matching braces visually and adds whitespace that makes the code
easier to deal with.

Note that I prefer two-space indents rather than tabs, as code tends
to wander off the right side of the screen too fast with tabs.

DJ

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019