CS 245 - Programming Languages

Programming Design Guide

You are expected to pay attention to your code organization. Your programming should adhere to the standards explained here. While some of the rules are due to convention, many more are pearls of wisdom distilled from solid software-engineering principles and all of them are essential for making your code readable and/or easy to maintain and modify/reuse. This document explains guiding principles. For more specific formatting rules please refer to the formatting guidelines.

Intentional Coding

  1. Every line of code should have a deliberate effect on your program. If you are not sure why a line is there, it shouldn't be. If your program stops working because you removed that line of code that you don’t understand, you need to understand it before you put it back.
  2. Within a single program, do not copy-and-paste code, only to change a few details. Instead, declare a function parameterize it. Do copy and paste code (changing as needed) between programs.
  3. Use constants to avoid so-called magic numbers - numerical values that are scattered all over your program and are difficult to understand or modify.
  4. Do not debug by trying all combinations. If you (or the debugger) pinpointed a line that doesn't work, it is important to spend the time to understand why. The most valuable gain of programming proficiency happens right here. A bug is not truly fixed unless you
    1. understood why it happend in the first place
    2. understood why changing the code the way you did fixed it

Scoping and Encapsulation

  1. Declare variables in the smallest scope possible. That is, prefer local variables over global variables.
  2. Kotlin and Go differ in their encapsulation apporaches. Since Kotlin is built on top of Java, it can use almost exactly the class-like encapsulation from Java. Aso you will be doing functional programming in Kotlin, this is not particularly significant. Still, it is good practice. Go encapulation is quite different but is easily understood. In short, be inspired by Java encapsulation and attempt to achieve similar ends.

Design

When programming in Kotlin, you must be as close to purely functional programming as the language permits. (Which is pretty darn close.) When programming in Go, you should carefully consider your imperitive code. Assignments will tend to be short, so be short.

Data Structure Design

Often, there is more than one way to store and represent data.
  1. Do not store the same thing more than once, or in more than one place.
  2. Choose the smallest storage so that the above is true and accomplishes your algorithmic goals.