On Coding Style

CS 300 Lecture 3.1

Bart Massey 2013-10-15

Overview

  • Misc notes
  • Pseudocode Concluded
  • Basics of Routine Construction

Misc Notes

Pseudocode Concluded

(In-class pseudocoding demo.)

Principles Of Routines

Overall principles:

  • Routines come from design

    • Not too little functionality
    • Not too much functionality
  • Routine interfaces should be narrow and understandable

  • Routines come with preconditions and postconditions

  • Routines should be coherent

Principles Of Routine Construction

  • Construction should be from pseudocode

  • Invariants should strengthen down the page

    • Handle corner cases first, then general case
  • Control flow should be as simple as possible

  • Optimization must not be a concern during construction

  • Maximal use of idiom

    • Flag all "surprising" code with comments

Book Example: A Bad Routine

  • I disagree with only a couple of critiques

  • I wish I could say I never see anything like this IRL

  • If you don't pick a standard coding style for your language, I will not even look at your code

    • Indentation
    • Whitespace

Let's Read Some Code

(Examination of my Ricochet Robots solver.)

Last modified: Monday, 14 October 2013, 11:53 PM