What coding standard?

Topics: Web Client Software Factory
Feb 25, 2007 at 11:29 PM
What coding standard are you guys using?
For example I thought the current MS standard for field names was “Do not use a prefix for member variables” (http://blogs.msdn.com/brada/pages/361363.aspx)
Coordinator
Feb 27, 2007 at 8:58 PM
Yes, believe it or not, we do use coding standards here. Sometimes it does not look like it, especially in some of the weekly drops.

We know about the MS standard on Brad's blog. That document was probably the base of the coding standards document I recieved when I joined the p&p team. However, I think that the internal doc I recieved has been modified and has evolved over time a bit to address the needs of our audience. As one of the few teams that actually ships source code, we need to ensure that our code is very readable.

As far as the underscores, I (and a number of us here at p&p) disagree with this rule. Sometimes consistent usage of a prefix ("_" in this case) or a suffix ("Field") is a lot more readable than explicit scoping (via the "this." convention). I like being able to determine the variable scope from the name. Also, a bunch of "this." code adds no value (except for the keyboard manufacturers who get me to buy replacements sooner due to typing 5 extra characters for every field I use in my code). ;-)

Of course, if it bothers you, you do have the code and could probably do a global search and replace. I've done so in the past when inheriting code that was written by someone who did not understand that there is only one true bracing style.

If you want to blame someone about the WCSF ignoring the rules, blame me. I was fairly relaxed about the coding standards.
Feb 27, 2007 at 10:19 PM
I actually was not attempting to criticize the source. I simply noticed a few divergences from the recommendations of brads blog, which usually seems to be a few steps ahead of the MSDN standards. It seems that the MS coding standards are in a process of consolidation, especially in terms of the coding style in the insides of classes. I was wondering if the P&P projects had a shared set of coding standards and, if there did, would these standards would eventually be made public.

Regarding modifying the project code to confirm to another standard: I generally find this to be a bad idea. Although I do check in the source for the third-party projects I try to only modify it if bugs are found. Even then I try to fix bugs without changing the core code. This is coming from experience. Once I did to a full clean of an external project and fixed a few bug while doing so. When the next version was release it made the upgrade a nightmare. It is very hard to do a compare when you have modified a large percent of the code to conform to a different standard.
Coordinator
Feb 28, 2007 at 4:40 AM
Simon,
The grumpy, evil, caffiene-deprived Michael must have taken that as criticism and responded this morning. The normal, good Michael would never do that. ;-)
Sorry about the misunderstanding.

I think MS coding standards will always be in a process of consolidation....
From what I understand talking to other dev leads (since all the teams I work with are wonderful), getting 10 developers to all agree on and do the same thing can be like herding cats. It's not impossible, but it may be more trouble than it is worth, and no one is happy at the end of the day. Now, think about getting 10,000+ (as a big, random number) developers to all agree to a standard and follow it. <insert Mission Impossible theme song here>

As far as updating the code to match your standard, you are right...that would cause problems come merge time on a project like this. Again, the evil, caffeine deprived Mike must have responded earlier.

Mar 5, 2007 at 10:49 AM
Edited Mar 5, 2007 at 10:57 AM
Michael,

Democracy doesn't apply to everything in a way that everyone is allowed to do whatever he/she wants. Democracy is also about respect for others and for hierarchy.

I really hate reading code that's not following the recomendations in Brad's blog. Not because it's Brad's/MS recommendation but because I feel it natural. I just use Brad's blog to justify my choice.

My boss follows the "m_" religion and I had to refactor all my code. I don't like it, but he's the rule maker. The fact that we're less than 500 or +10,000 like you, shouldn't matter.

Making choices is not always easy. If you are the one that has to make them, live with it. If you are the one that has to abide, live with it.

Nevertheless, code from p&p should run unmentioned through Visual Studio's static code analisys and FxCop.

And the caffeine deprived Mike can answer because I'm criticizing the choice. :)

--
Paulo Morgado
http://msmvps.com/blogs/PauloMorgado/