I have a rather theoretical question. My company has a working standard (documented) that is rather extensive regarding C++ but is almost none existent when it comes to C#, where the only directive is that the coding standard should follow Microsoft’s style guidelines for C#. MSDN does have guidelines, but this causes a rather large difference between code in both languages in our companies’ code.
Here are a few coding standards we have for C++ (nothing new mind you):
-
Class member names should start with m_ and proceed in camel case i.e.
bool m_isValid; -
Method params should start with _ i.e. and proceed in camel case
void Foo(bool _isValid); -
local variables are regular camel case i.e.
bool isValid;
This makes for very readable code when reading long functions, since you immediately know what is a member, what is a parameter, and what is a local variable.
Now when it comes to C#… The usual practice is camel case for all three. It is much harder to read, and you have to hover over the variable or click it to know which one it is.
If it where your decision, would you enforce the same coding standards for both languages? Would you enforce most of the same coding standards? Or would you go with a different language different standards approach?
Thanks…
Absolutely not. I’d follow the normal conventions for C#. If you try to make code in language look like code in another, you’re likely to start using idioms from that language too… and end up speaking C# with a C++ accent.
So wherever possible, avoid creating long methods… I very rarely find it a problem to have all three kinds of variable using the same conventions – whereas long methods end up being painful whatever conventions are used.