views:

150

answers:

5

Normally each person takes their own "calligraphy" to write code, however, is there a "standard" or any way that you feel clear and easy to allow the code becomes "readable" by any programmer who is using your code?

Personally I use (a simple example):

if (myVar == 5)
{
    // easy to identify where the IF was launched, IMHO.
}

Instead of:

if(myVar == 5){
    // 
}
A: 

For the languages that have a community standard (Python's PEP008 for example), you follow that. For other languages, the answer isn't as easy.

retracile
+2  A: 

This is a topic that starts as much of a debate as which is the right end of an boiled-egg to open first.

see

One recommendation: When you edit any pre-existing source file, stick to whatever convention is currently in place (assuming that there is one)

djna
A: 

Doesn't really matter as long as it's universal throughout the application.

If you're going to put the { on the same line as the call, then do it EVERYWHERE.

Much like in baseball. As long as the umpite keeps the strike zone consistent, everyone is happy.

Jack Marchetti
A: 

Code Complete goes over your exact example. It comes down to a matter of preference, expect to see both and learn to read both. The book is a great reference for your question

As far as your example, I prefer the second method you specified, and for C#, StyleCop enforces having your brackets on seperates line like that. I follow the StyleCop suggestions for everything as I can understand the reasoning behind them, with the result being clear-to-read code.

Will Eddins
A: 

No, each developer has a personal style which they're most comfortable in.
Some developers have similiar styles, but there isn't one standard way.

The best you'll get is a defined standard, which everyone is expected to follow.
This will feel comfortable to some, and uncomfortable to others, based on how close it is to their own personal style.

Bravax