What code convetion do you use?

Started by
20 comments, last by Fenrisulvur 14 years, 2 months ago
Hi! What code convetion do you use in your company? Or do you create a new one? (I'm not talking about when I code alone) I will apreciate if you write any link. Thanks a lot.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
Advertisement
Quote:Original post by ricardo_ruiz_lopez
Hi!

What code convetion do you use in your company? Or do you create a new one?
(I'm not talking about when I code alone)
I will apreciate if you write any link.

Thanks a lot.


I try and emulate this as much as possible for C#. I don't follow it completely, but for the most part, emulating the standards set by MSDN example code can do you no harm.

My company has no official coding standard, unfortunately.
We follow the MSDN one pretty closely. It doesn't really make much sense to invent a new one when so much of your code makes such heavy use of the standard libarary, it'd look a little out of place, really.

Edit: Oh sorry, it's not specific to just C#... I don't know why I read that into the OP :) For C++ I tend to use a standard library/boost coding style, but that's not in a company environment. In my last job, we wrote C++ similarly to how we do C# now (though with a 'C' prefix for class names... a strange practice that I do not understand to this day, probably borrowed from ATL/MFC).

[Edited by - Codeka on February 8, 2010 6:07:34 PM]
I follow the C# recommended spec pretty much verbatim, in both C++ and C#. Other languages, I sorta make it up as I go >_<
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Apps Hungarian (not Systems Hungarian).

There was actually a big email-fight at work today regarding standards, resulting in this:
My work uses the default MSVS settings, PascalCase for classes/publics, camelCase for locals/params/privates, comment only the peculiar cases... pretty standard stuff. For C# and java anyways. C++ is pretty standard C++ notation.

For my personal projects I change the default settings to not put { on a newline. I also will always use braces for conditionals, and always parenthesize a return value.

And oh, how I await the day that IDE autoformatting is good enough to let everyone do whatever they want and then reformat it to some convention for check-in.
When we started up the company I didn't want to spend a lot of time on style so we used the Google C++ style Guide with very little modifications. Also all of the C# code is following the C# recommended spec.
Braces on new line, spaces instead of tabs, etc., the typical MS C# style. The specifics don't matter too much since it's just formatting; what's important is that you pick a standard and apply it consistently.

What's considerably more important are things like naming, exception usage, and general code design. For this I highly recommend Framework Design Guidelines by Krzysztof Cwalina and Brad Abrams. Despite its name I find it highly applicable to non-framework code. The chapter on naming in particular is hugely important and useful.

I'll generally use whatever style is most common in the language I'm using.

My bracing in C++ is different from some styles in that it puts braces on newlines for bracing levels deeper than two levels or sections that are deeper than one level and are <10 lines long. Eg:

// C#public class Foo{   public static void Main()   {      int someVariable = 0;      Console.WriteLine(someVariable);   }}// Javapublic class Thing {   public void bar () {      System.out.println("Foobar");   }}// C++class something{public:   something() {      // this is only a couple of lines      foo();      bar();   }   void derp()    {       if (/* test here */)          foo();       else          bar();   }};// still C++void free_function(){   if (/* test */)   {       if (/* another test */) {         // something         // something      } else {         // something else         // something else         // something else      }   } else {      // something else   }}; Lisp(defun factorial-demo (x)   (if (= x 1)     1     (* n (factorial-demo (- n 1)))))// Scalaobject Hello extends Application {   def foo = System.out.println("Foo");   def bar (x: int) = {     if (x == 5) {       System.out.println("bar");     } else {       System.out.println(x);     }   }}
Thanks a lot, very interesting.

I found a lot of info here:
http://en.wikipedia.org/wiki/Programming_style

All opinions are welcome.

By the way, does anyone work in a company without them? What do you think?

Thanks.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.

This topic is closed to new replies.

Advertisement