team178 / CaptainFalcon

2014 Competition Robot - Aerial Assist
Other
1 stars 0 forks source link

Decide and establish coding conventions #6

Open gluxon opened 10 years ago

gluxon commented 10 years ago

It's important in a programming team that everyone agrees on a language to use within the programming language chosen. This way, the code base isn't an unfamiliar jungle in its different parts to newcomers.

The general rule for coding style is that code is written in the way that it takes the least amount of mental effort and energy to decipher its intentions. Consider the basic indent example:

if (hours < 24 && minutes < 60 && seconds < 60) {
    return true;
} else {
    return false;
}

vs

if  ( hours   < 24
   && minutes < 60
   && seconds < 60
)
{return    true
;}         else
{return   false
;}

-- from http://en.wikipedia.org/wiki/Programming_style#Code_appearance

gluxon commented 10 years ago

I suggest agreeing on the more basic questions to start

  1. The classic. Which indent style? K&R or Allman? Please checkout -> http://en.wikipedia.org/wiki/Indent_style
  2. What is an indent? 4 spaces? 2 spaces? Tab? Keep in mind NetBeans defaults to tabs that are equivalent to a ridiculous 8 spaces in width.
  3. When should a new line be used?

Regarding #3, I personally think code should be written like a coherent essay. New ideas or commands that affect different areas of the robot should be separated by a line.

gluxon commented 10 years ago

I'm writing this as a separate comment since I'm almost certain everyone here doesn't really believe coding conventions are that important.

Let me summarize why they are:

Don't end up like Apple. They had a critical bug in their security very recently that could have been solved by someone reviewing their code for coding conventions. Check it out, it's quite hilarious and I challenge everyone to see if you can find the bug. (It's really simple.)

https://www.imperialviolet.org/2014/02/22/applebug.html

robstolarz commented 10 years ago

My opinion:

omit blocks when possible space operators if you feel like hit tab to indent and always keep indents nice

set these as your NetBeans Formatting prefs and liberally highlight + Alt+Shift+F

indent/newline function arguments if too much crazy is going down newline every statement unless there's a reason you shouldn't don't under any circumstance 80 character wrap cause we have modern screens capable of displaying more than that.

that's all you gotta do

Please don't change my formatting for me :)

gluxon commented 10 years ago

I hope you don't mind that I updated your comment to demonstrate how much easier it is to read as bullets rather than a very large sentence with 6 comma splices. (I'm sorry. Not to pick on you personally but it was a perfect example I couldn't miss. Hope this doesn't come off as devilish and mean :heart:)

gluxon commented 10 years ago

@ThatTreeOverThere

robstolarz commented 10 years ago

@gluxon Not omitted:

if( branch ) { 
    return true; 
} else { 
    return false;
}

Omitted:

if( branch ) 
    return true; 
else 
    return false; 
gluxon commented 10 years ago

Blocks are different from braces though.