Difference between revisions of "Coding Style"

From Mineserver Wiki
Jump to navigation Jump to search
** '''Instance variables''' should usually be accessible through getter and setter methods and thus be private. In some cases having them public is fine (e.g. when they're accessed all over the place and modifiying them happens all over the place as well. Usually this is the case for "dumb classes" used as pure data structures. We should consider using a '''struct''' instead for these cases.). Also, don't use prefixes for public instance variables, since it's ugly to use. For private instance variables we could choose to use '''m_foo''' and have a getter method be just '''foo()''' and a setter '''setFoo()'''. 
** '''Instance variables''' should usually be accessible through getter and setter methods and thus be private. In some cases having them public is fine (e.g. when they're accessed all over the place and modifiying them happens all over the place as well. Usually this is the case for "dumb classes" used as pure data structures. We should consider using a '''struct''' instead for these cases.). Also, don't use prefixes for public instance variables, since it's ugly to use. For private instance variables we could choose to use '''m_foo''' and have a getter method be just '''foo()''' and a setter '''setFoo()'''. 
* '''Namespaces''': We probably should use them.
* '''Namespaces''': We probably should use them.
−
* '''Codeblocks''':
+
* '''Codeblocks''': (Use braces always for clarity and to prevent bugs while editing code)
−
if(true)
+
if(true) {
      foo = bar;
      foo = bar;
−
+
}
 +
    if(true)
    if(true)
    {
    {