AboutSQL Server, Analytics, .Net, Machine Learning, R, Python Archives
About Me
Mitch Wheat has been working as a professional programmer since 1984, graduating with a honours degree in Mathematics from Warwick University, UK in 1986. He moved to Perth in 1995, having worked in software houses in London and Rotterdam. He has worked in the areas of mining, electronics, research, defence, financial, GIS, telecommunications, engineering, and information management. Mitch has worked mainly with Microsoft technologies (since Windows version 3.0) but has also used UNIX. He holds the following Microsoft certifications: MCPD (Web and Windows) using C# and SQL Server MCITP (Admin and Developer). His preferred development environment is C#, .Net Framework and SQL Server. Mitch has worked as an independent consultant for the last 10 years, and is currently involved with helping teams improve their Software Development Life Cycle. His areas of special interest lie in performance tuning |
Wednesday, November 01, 2006I used to be an end brace man…
Don’t worry, I’m not about to burst into song (that would be unpleasant)!
Over the past two decades, I have shed most of my personal biases towards coding style. Where once I would have argued vehemently for a particular syntax just because I currently used it, I am now always happy to be shown a better or more logical way. I still believe that any coding convention should be backed by the reason it makes the code more readable, rather than just personal preference. When there is no benefit in one style over another, then personnal preference obviously comes into play. But the one thing I can’t shed is the placement of curly braces in the C style languages (C/C++/C#). Now I’m not trying to ignite a holy war here. For the first 3 or 4 years I programmed in C and C++, I positioned the curly braces like this: if () { … } But over time and exposure to many other languages (and many other programmers’ styles) I felt that it was unbalanced so I switched my style to if () { … } where I remain. To me, the semantics suggest Begin … End, so the second style seems more natural. This seems to be the default standard for the Visual Studio IDE. I had taken heart in the fact that the majority of the code I’ve seen coming out of Microsoft generation tools has followed this style, but to my horror I recently spotted generated code that follows “1st brace at the end of line”! After a bit of nosing around it seems it’s roughly 60/40. Even the .NET Framework Design Guidelines use the first style, despite the fact that Lance Hunt’s and other popular and freely downloadable coding guidelines specify the second. One thing I don’t understand is why developers who adhere to the second style don’t write their methods the same way? i.e. public int MyMethod(int x, int y) { return h = x + y; } So all the C# coders who read this blog, please leave a comment indicating your preferred brace style. I’m curious, so don’t be shy! |
ContactMSN, Email: mitch døt wheat at gmail.com LinksFavorites
Blogs |