Skip to content
TStream edited this page Apr 21, 2017 · 3 revisions

Its easier to read code when its all the same style

  • Indentation:

    • There is more than one way of indenting code. Some ways included but are not limited to:

Style 1

public void foo() {
    if (maybe) {
        do_stuff();
        do_more_stuff();
    } else {
        dont_do_stuff();
    }
    done_stuff();
}

Style 2

public void foo() 
{
    if (maybe) 
    {
        do_stuff();
        do_more_stuff();
    } 
    else 
    {
        dont_do_stuff();
    }
    done_stuff();
}

Style 3

public void foo() 
{ if (maybe) 
    {  do_stuff();
        do_more_stuff();
    } 
    else 
    { dont_do_stuff();
    }
    done_stuff();
}
  • Name Scheme:

    • popular options:
      • camelCase: First letter of each word is capitalized, except the first word, like: someRandomFunction()
      • underscores: Underscores between words, like: some_random_function()
  • if you are starting a project form scratch pick a style and stick with it

  • if you are working with others, agree on a style and stick with it

  • if you are working on someone else’s code, stick with their style

  • No best style. Just be consistent.

Clone this wiki locally