Is there a code style guide I should be following

Topics: Rawr.Base
Oct 12, 2009 at 5:13 PM

I am working on cleaning up the Elemental shaman code (e.g. add comments, consistent bracing) but I am not sure if there is a code style guide I should be following. For example I noticed there are some variables that are public, others are hidden behind properties and others just used auto-implemented properties. I don't know which one is the preferred method.

Oct 12, 2009 at 5:19 PM

Well it is a mix of code written by me and code from Trolando.

Could you go more into detail on what you are referring to?

Oct 12, 2009 at 5:28 PM
Well I want to be sure that the work I do fits the prefer style. At work
we have a set style guide for coding. For example it is preferred to put
braces on new lines for if statements and always included them for each
case:

(bad style - work)
if ( a = 4 ) {
... do something
}
else
.. do another thing


(good style - work)
if ( a = 4 )
{
... do something
}
else
{
... do another thing
}

Second example is to not put more than one class in a file. The reason
behind this was that it is much easier to locate where a class is
defined by searching for a file with the same name.

Final example is to use predefined constants instead of magic numbers
(e.g. using public static int MaxValue = 5 instead of using the number 5
all over in the code).

These are the kinds of things I was wondering about.
Developer
Oct 12, 2009 at 5:45 PM

If you are going to be the person taking over Ele then do it how you feel most comfortable. Judging from the above statement you are heading in the direction I would ask for personally and I'm probably one of the most OCD people on the team.

Developer
Oct 12, 2009 at 5:49 PM

Amagad you are the one that's been OCD'in in my code!

 

I'm slightly OCD about code as well and I prefer the second one with

if ()
{
}
else
{
}

 

Although I think Jothay likeys the

if () {
}
else {
}

 

as I suddenly found some of them in my code :P

 

Honestly? It doesn't matter much for me as the indenting is what I read code by anyway. Indentation happens exactly the same, although Jothay's way takes less vertical screen space.

Oct 12, 2009 at 5:56 PM
On Mon, 2009-10-12 at 10:45 -0700, Jothay wrote:
> From: Jothay
>
> If you are going to be the person taking over Ele then do it how you
> feel most comfortable. Judging from the above statement you are
> heading in the direction I would ask for personally and I'm probably
> one of the most OCD people on the team.

I have played an elemental shaman for the last year. So I think I have
good background to do. Right now I don't understand how the internal
code works but that takes time while starting up something new.
Developer
Oct 12, 2009 at 6:05 PM

You only just now noticed those TNSe? That happened like, a LONG time ago...

and to clarify:

if (thisValue >= 0) {
    // exec statement
} else {
    // exec other statement
}
nice, neat, concise, less scrolling, who wouldn't want that?

Developer
Oct 12, 2009 at 6:18 PM

I know, I had to fix up a typo in my own suddenly modified code XD.

 

And I agree, ideal is probably if () {, but I'm not so sold on the } else { one. Indenting is the most important  for me.

Coordinator
Oct 12, 2009 at 6:38 PM

The general rule throughout Rawr is to follow Microsoft standard practices.

public int PublicMethod(int input)
{
    if (true)
    {
        int localVariable = 0;
        DoThis();
    }
    else
    {
        DoThat();
    }
}
private int _privateField = 0;
public int PublicField = 0;
public int PublicProperty { get; set; }

However, in models' code, it's really up to the model developer(s), since they're the ones working on it the most.

Developer
Oct 12, 2009 at 9:47 PM

I try to stick as much as possible to the model Astrylian put forth as an example for ProtWarr, just because that's what has been required at all the various places I've worked so it's force of habit.

I find it to be the most readable overall.

Although sometimes some shorthand stuff (especially with single if() statements doing one thing) sneaks in now and again.

Coordinator
Oct 13, 2009 at 12:07 AM

I'm not that picky about what coding style others use, but I'm less forgiving about naming guidelines. It would be nice if more people working on Rawr.Base followed the Microsoft guidelines http://msdn.microsoft.com/en-us/library/xzf533w0(VS.71).aspx

Developer
Oct 13, 2009 at 12:24 AM

Bracing practices are a religious debate.  You like your ways, and I like mine, and what reads well for someone, might make another dev's eyes bleed.  If you're the only one in there, then have your way with it.  If you have to share space, then come to a consensus.  I know at work, we *tend* to brace as per Astry's latest example.  And I have a personal pet peeve about seeing the brace start on the same line as the declaration, or statement.  But again, that's just me. 

Coordinator
Oct 13, 2009 at 12:30 AM

I personally don't really care as to the placement of the braces. When I first started programming I left the braces on the next line. However now-a-days, I tend to keep the braces right next to the parenthesis.

Oct 13, 2009 at 12:14 PM

Err you know that I am the current Elemental developer, right?

Oct 13, 2009 at 11:06 PM
No. I was not aware that there was an elemental shaman developer. The
site said there was need of one. Since I am one and can code in C# I
applied.