User Tools

Site Tools


epgy:ai13:notes_on_style

Table of Contents

Notes on Style

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