Coding Guidelines

  • Your code should look nice and be legible. Use an automated code formatter. Keep your functions short (under a page of text) and your classes/files reasonably long (1000+ LOC should ring an alarm). Always delete commented-out code – it’s already in the Git repository if it’s ever needed again.
  • Respect the Single Responsibility Principe. One class/file should either talk to the DB, or output GUI, not both.
  • Give clear, descriptive names to your classes, functions and variables. This is art (and it’s really hard), so practice it.
  • Extract commonly used numbers, strings etc. into (well named) constants. “Magic numbers” in code are bad.
  • Respect the Don’t Repeat Yourself principle. Reuse existing code, refactor code that looks similar or performs similar tasks. Copy-paste is worse than plague.
  • Write documentation with common sense. Prefer good names and short functions to comments. Document your public APIs/interfaces.
  • Prefer functional style of programming, avoid side-effects.
  • Treat any warnings from your compiler/toolchain as important and helpful information.
  • Crash early, once you detect a problem throw an exception and log some data to help you fix it later. Set up the application so that any errors will be sent to you by mail.
  • Use a build/dependency management system, such as Maven, CocoaPods or similar.