Fork me on GitHub
  May 22, 2018, 01:51:29 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Coding Style  (Read 6059 times)
bakkdoor
Developer
Newbie
****
Posts: 8


View Profile
« on: December 07, 2010, 01:12:26 am »

Talked to Psoden today in irc and agreed that we need a coding style, immediately Smiley

Here's a proposal: http://mineserver.be/wiki/Coding_Style
Comments welcome.
Logged
deoxxa
Administrator
Newbie
*****
Posts: 28


View Profile
« Reply #1 on: December 07, 2010, 01:56:08 am »

I like it, no complaints here!
Logged
Manhim
Developer
Newbie
****
Posts: 10


View Profile
« Reply #2 on: December 07, 2010, 02:51:53 am »

For less confusion I suggest getFoo() for getters.
Logged
Andrew
Developer
Newbie
****
Posts: 9


View Profile
« Reply #3 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.

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;

A better way of doing the same thing
Code:
if (!obj) { return; }
if (!foo) { return; }
if (!bar) { return; }

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();

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.
« Last Edit: December 07, 2010, 08:22:31 am by Andrew » Logged
bakkdoor
Developer
Newbie
****
Posts: 8


View Profile
« Reply #4 on: December 07, 2010, 11:39:35 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.

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 Cheesy

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.

+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;

A better way of doing the same thing
Code:
if (!obj) { return; }
if (!foo) { return; }
if (!bar) { return; }

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();

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.
« Last Edit: December 07, 2010, 11:42:07 am by bakkdoor » Logged
Manhim
Developer
Newbie
****
Posts: 10


View Profile
« Reply #5 on: December 07, 2010, 10:36:06 pm »

I'd use a prefix only for private members like _privateMember;

For public ones it would be PublicMember or publicMember, whichever is the best.
Logged
louisdx
Newbie
*
Posts: 12


View Profile
« Reply #6 on: March 31, 2011, 11:39:58 pm »

Regarding getters and setters, how about using a single function with a const overload to return both lvalues and rvalues?
Logged
MechWarrior001
Newbie
*
Posts: 31


View Profile
« Reply #7 on: May 22, 2011, 06:39:45 am »

In MS VC++ 2010 Express I'm getting a bunch of warnings concerning using sprintf_s instead of sprintf, fopen_s instead of fopen, and localtime_s instead of localtime. While probably not necessary, it might be a good idea to switch to the *_s commands, if for nothing else than good coding practice.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!