epgy:ai13:notes_on_style
Notes on Style
Why do we care about style?
Better style leads to fewer bugs
Allows you to reuse code
Helps others who have to interface with your code
Write quality code faster
Style guidelines for java
variable naming
make your variable names descriptive, useful, concise
integerValuedCounterForNumberOfLoops vs. i
phonebook vs. map
isTrue vs. hasUpdates
case is important - StudlyCaps
lowerCaseCamel for variables
UpperCaseCamel for classes
ALL_CAPS_UNDERSCORES for constants
magic numbers
using numbers without values
int counter = 17; vs. int counter = INIT_COUNTER_VALUE
graph of likelihood a number should be in your code
saves you from using incorrect numbers,
allows code reuse
makes code readable
tabing \ spacing
consistency is the most important factor
however, standards exist
comments
the total sum of above should be nicely readable code
nevertheless, comments are great
two types of comments
there are inline comments
use when you need to explain tricky lines
if what you are doing is not obvious
and there are block comments /* … */
use at method headers
for detailing the function of a method
look into javadoc if you are interested in comments
java writes its own documentation!
java api generated by java doc
decomposition
a school of thought for writing code:
how do you separate each task into smallest components
organize your ideas - how do you break your problem up into smaller chunks
write pseudocode - make note of where code can be judiciously reused
decompose as you go
when i write code, i often use methods, constants i have not yet written
fill them in later
/soe/sherol/.html/teaching/data/pages/epgy/ai13/notes_on_style.txt · Last modified: 2013/07/18 13:14 by ffpaladin