Jump to content
  • Advertisement
Sign in to follow this  
riruilo

What code convetion do you use?

This topic is 3050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
I follow the C# recommended spec pretty much verbatim, in both C++ and C#. Other languages, I sorta make it up as I go >_<

Share this post


Link to post
Share on other sites
Apps Hungarian (not Systems Hungarian).

There was actually a big email-fight at work today regarding standards, resulting in this:

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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);
}
}

// Java
public 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)))))

// Scala
object 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);
}
}
}


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!