Mineserver > Development
Coding Style
bakkdoor:
Talked to Psoden today in irc and agreed that we need a coding style, immediately :)
Here's a proposal: http://mineserver.be/wiki/Coding_Style
Comments welcome.
deoxxa:
I like it, no complaints here!
Manhim:
For less confusion I suggest getFoo() for getters.
Andrew:
I personally don't see the point behind using outdated hungarian notation by putting m on all the member variables.
Both Microsoft and Bjarme Stroustup recommend against it and that's enough for me. We're not coding in C and need to keep check of if our variables are "members" of our "class"
this->m_foo.. you already know it's a member of the object you're calling.
I also suggest putting brackets on all if statements as it's very easy to create a bug by proxy of someone else editing your code. The only reason no one really does is simply laziness (myself included).
I think the most important thing however is the way people write code and the names they use for methods. I think it's more important then general syntax and how many spaces an indent is.
A bad example with difficult to read code..
--- Code: ---if (obj)
{
// insert many lines of code
if (foo)
{
// insert many lines of code
if (bar)
{
// insert many lines of code
}
}
}
return;
--- End code ---
A better way of doing the same thing
--- Code: ---if (!obj) { return; }
if (!foo) { return; }
if (!bar) { return; }
--- End code ---
A bad example with method naming simply because everyone uses a different name for getting similar data across classes.
--- Code: ---Foo foo;
Bar bar;
foo->getName();
bar->getTitle();
--- End code ---
My personal experience is that when working in teams the previous two examples are much more important then making sure everyone's syntax is similar.
bakkdoor:
--- Quote from: Andrew on December 07, 2010, 08:19:39 am ---I personally don't see the point behind using outdated hungarian notation by putting m on all the member variables.
Both Microsoft and Bjarme Stroustup recommend against it and that's enough for me. We're not coding in C and need to keep check of if our variables are "members" of our "class"
this->m_foo.. you already know it's a member of the object you're calling.
--- End quote ---
I'd prefer no prefixes as well, makes it harder to read imho. But I'm fine with using them if the majority demands it :D
--- Quote ---I also suggest putting brackets on all if statements as it's very easy to create a bug by proxy of someone else editing your code. The only reason no one really does is simply laziness (myself included).
I think the most important thing however is the way people write code and the names they use for methods. I think it's more important then general syntax and how many spaces an indent is.
--- End quote ---
+1
--- Quote ---A bad example with difficult to read code..
--- Code: ---if (obj)
{
// insert many lines of code
if (foo)
{
// insert many lines of code
if (bar)
{
// insert many lines of code
}
}
}
return;
--- End code ---
A better way of doing the same thing
--- Code: ---if (!obj) { return; }
if (!foo) { return; }
if (!bar) { return; }
--- End code ---
A bad example with method naming simply because everyone uses a different name for getting similar data across classes.
--- Code: ---Foo foo;
Bar bar;
foo->getName();
bar->getTitle();
--- End code ---
My personal experience is that when working in teams the previous two examples are much more important then making sure everyone's syntax is similar.
--- End quote ---
Navigation
[0] Message Index
[#] Next page
Go to full version