[prog] C and curly braces - question of style?

Sue Stones suzo at spin.net.au
Mon Aug 23 17:33:41 EST 2004


Angelina I prefer your way of doing things because that is the way I was 
taught.  Personally I think that people find it easier to read if the 
braces are used the way they are most familiar.  And that is the only 
thing that makes either of the styles that you mentioned easier to read.

It is also the reason why you should think about style as soon as 
possible.  Because the more you are familiar with one style the harder 
it is change later on.  If you are working with the people who say that 
the second style of code is easier to read, then getting used to that 
way of both reading and writing code now would be an advantage.

Working with other people is probably the most important reason to 
choose a style.  I had a boss who said when I first worked there that he 
had no preferred style of anything, but when he read my code he would 
change my bracketing style and number of white lines to his preferred 
method and I would come back and find sections of my code 
unrecognisable.  Especially annoying when I would leave a number of 
white lines in the code to say "this is where I was up to".

There are other styles of placing braces that I have seen that are much 
more compact, which I therefore find harder to read.

while(whatever){statement;statement; statement}

while(whatever){statement;
	statement;
	statement}

and similar I haven't bothered to remember the details.

Akkana Peck wrote:
>>On Mon, 2004-08-23 at 11:10, Jacinta Richardson wrote:
>>
>>>But as someone else has said, whichever you choose *be consistent*.  In 
>>>particular use a consistent indent level.  One tab, or x many spaces... 
>>>Don't indent in some places and not in others.
>>
>>I prefer that people indent using tabs, not spaces. If you want a
>>narrower tab level than is standard, set it in your editor.
> 
> 
> I dislike code indented with tabs.  

I think indenting has much more effect on code that is looked at under 
different conditions than bracing style.  I like tabs.  Easier to type. 
  Easier to resize.  Mostly when I have to print code out I have to 
transfer it to a word processor anyway, so the change in tab size is 
either maintained or readjusted to suit the work processor.

The biggest problem I have found is editors that will automatically 
indent for you and will decided for themselves to use either spaces or 
tabs and ignore what you ask for.  I am frequently in a situation of 
looking at code under both windows and Linux and its virtually 
impossible to get anything to intended properly, and look the same under 
the two OS's.

sue





More information about the Programming mailing list