forked from Dev-Outreach/bad-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Consistent style
TStream edited this page Apr 21, 2017
·
3 revisions
-
- 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();
}-
- popular options:
- camelCase: First letter of each word is capitalized, except the first word, like:
someRandomFunction() - underscores: Underscores between words, like:
some_random_function()
- camelCase: First letter of each word is capitalized, except the first word, like:
- popular options:
-
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.