How I Learned to Stop Worrying and Love the Coding Conventions
Exhibit #1:
public class MyClass
{
public int MyFunc(int x, int y)
{
return x + y;
}
}Exhibit #2:
public class MyClass{
public int MyFunc(int x, int y){
return x + y;
}
}If you have some programming experience you might recognize the two styles. One of which common in your projects and the other looks strange and might even cause you a slight discomfort or bad feeling at the pit of your stomach. Some software developers have been arguing about which is better for as long as I can remember and to tell the truth I was one of them until recently.
I work mostly in C# and the majority of projects/demos/tutorials out there use the first convention. I used to argue that itâs better because it makes the code more readable and besides thatâs the Visual Studio default and if itâs good enough for Microsoft itâs good enough for me. Then I got to my current employer where the official coding standard defines option number 2 as well as other conventions and it was hard. Each time I glanced at my code I had the urge to re-format, it made me feel âdirtyâ. After a while I got used to the new curly brackets location but it still felt wrong to me. One of my responsibilities is to make sure that all of the teams projects follows the official companyâs coding specifications some of which I donât fully agree with.
Iâm a fan of this developerâs life podcast and yesterday I heard the latest show Obsession where Scott and Rob talk to several developers about their obsessions and than it hit me â the feeling I have whenever I see code that formatted âwrongâ is my little OCD (obsessive compulsive disorder), itâs one of the obsessions I picked up on the way, I need to code to be ârightâ, similar behavior can be found when developers argue what is better â camel-case or Pascal-case, spaces or tabs, VB.NET or C# and so on. Many of these arguments are valid but sometimes we just miss the point, just because we feel good/bad with something doesnât mean that itâs right it just mean weâre more comfortable with it and thatâs ok.
As for coding standards there is a valid reason theyâre in place â we want all of the companyâs source code to follow the same rules. An important goal â even at the price of making you feel good about how the code looks.
One final note â this can only go so far, if the rules make the code less readable and the developers less effective â you should make an effort to change them.
Reference: How I Learned to Stop Worrying and Love the Coding Convensions from our NCG partner Dror Helper at the Helper Code blog.

