-1

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):

  1. Class member names should start with m_ and proceed in camel case i.e. bool m_isValid;

  2. Method params should start with _ i.e. and proceed in camel case void Foo(bool _isValid);

  3. 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...

sprite
  • 3,724
  • 3
  • 28
  • 30
  • How will you be choosing the right answer? – hookenz Mar 28 '12 at 17:31
  • 1
    Not really a programming question per se, both languages have differences in style and features that make a unified standard difficult at best. Throw Java in the mix too and you'll have a major headache. – James Michael Hare Mar 28 '12 at 17:31
  • @MattH My guess: Which ever one agreed with their assumptions. Hence why we voted to close, I'm guessing ;) (Of course, I know you were asking your question in order to illuminate the reason for our votes to close) – Andrew Barber Mar 28 '12 at 17:33
  • 1
    The problem with reading long functions is solved by writing short functions. – Bo Persson Mar 28 '12 at 17:39
  • A down-vote? Really? Similar questions to this one weren't down-voted. There just wasn't one exactly like this one. Whoever down-voted this question, I would like to at least know why. Thanks. – sprite Mar 28 '12 at 21:11
  • Two different languages, two different coding standards. Why would you expect otherwise? – Robert Harvey Mar 29 '12 at 23:01

2 Answers2

5

If it where your decision, would you enforce the same coding standards for both languages?

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.

This makes for very readable code when reading long functions

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I simply had to accept Jon Skeet's answer. Couldn't resist. No seriously, this makes lots of sense. @Matt H, this is how I chose: A good argument. Thank you Jon. – sprite Mar 28 '12 at 21:09
5

I've worked in different companies and some like hungarian notation and some don't. Coding style is more of a matter of opinion so I would do what's most suited to how you and your team like to develop.

Darren
  • 68,902
  • 24
  • 138
  • 144
  • Exactly; it's largely a matter of opinion. (My opinion happens to match - and was formed in part by - Jon Skeet). That, incidentally, is a big reason why this question was closed. +1 for this answer, anyway. – Andrew Barber Mar 28 '12 at 17:36