Monthly Archives: December 2010

Coding standards

I’m currently working on a C++ project and the coding standard problem raised again. And again, nobody in the team agree about the style/naming format to adapt. C++ sounds somewhat cursed on this topic. After so much years of existence, no precise coding rules has emerged and everyone is almost authorized to code as he wants to, making the whole project source code quite very heterogeneous and obviously hard to maintain. Java has a clean coding rules and almost everybody is following it without arguing. C# seems to have also a common coding standard, but it doesn’t seems to be that followed. That could be my very small experience in C#, I stand to be corrected. Back to C++. You may think: ‘what a big deal, just pick some rules and stick to it’. That’s the ultimate goal, thanks for your input ! But then, you have to please everyone habit and it’s not that easy. So you’re going to compromize on many thing and at the end, nobody is really happy with the result.

But wait, it’s a PureBasic blog, no ? That’s right and I wondered if we needed strict PureBasic coding standard, but after some thoughts it doesn’t seem to be needed and i will explain why:

– PureBasic comes with a big command set, which implicitly set the the name rules for the function/procedure naming: CamelCase. One down. In C++ you have to choose how to name your functions, your methods and your class. Candidate are numberous: myMethod(), MyMethod(), my_method(), mymethod() and so on.

– The constants are prefixed by a ‘#’ in PB, so it can’t clash with variables or anything else. PureBasic comes with a lot of predefined constants, all in CamelCase as well, setting a de facto standard. Again in C++ you have many way to name them: MyConstant, MY_CONSTANT, kMyConstant etc.

– PureBasic help and demo examples are very consistent and always share the same syntax rules which helps to guide the newcomers to format the code the same way.

– There is no “{}” in PureBasic, so the flamewar between K&R and GNU style is avoided, thanks !

When looking at the code snippet pasted on the, I feel there is a common style and it’s very cool to see that. It doesn’t take long to get a grip on someone else code, and that’s a very important part of a programming tool.

Merry Christmas !