What To Do While You Are Coding

  • Always be aware of what you are doing.
  • Can you explain the code, in detail, to a more junior programmer? If not, perhaps you are relying on coincidences.
  • Don’t code in the dark. Build an application you don’t fully grasp, or use a technology you don’t understand, and you’ll likely be bitten by coincidences. If you’re not sure why it works, you won’t know why it fails.
  • Proceed from a plan, whether that plan is in your head, on the back of a cocktail napkin, or on a whiteboard.
  • Rely only on reliable things. Don’t depend on assumptions. If you can’t tell if something is reliable, assume the worst.
  • Document your assumptions.
  • Don’t just test your code, but test your assumptions as well. Don’t guess; actually try it.
  • Prioritize your effort. Spend time on the important aspects; more than likely, these are the hard parts. If you don’t have fundamentals or infrastructure correct, brilliant bells and whistles will be irrelevant.
  • Don’t be a slave to history. Don’t let existing code dictate future code. All code can be replaced if it is no longer appropriate. Even within one program, don’t let what you’ve already done constrain what you do next — be ready to refactor.
  • Duplication: You’ve discovered a violation of the DRY principle.
  • Nonorthogonal design: You’ve discovered something that could be made more orthogonal.
  • Outdated knowledge: Things change, requirements drift, and your knowledge of the problem increases. Code needs to keep up.
  • Usage: As the system gets used by real people under real circumstances, you realize some features are now more important than previously thought, and “must have” features perhaps weren’t.
  • Performance: You need to move functionality from one area of the system to another to improve performance.
  • The Tests Pass: Yes. Seriously. We did say that refactoring should be a small scale activity, backed up by good tests. So when you’ve added a small amount of code, and that one extra test passes, you now have a great opportunity to dive in and tidy up what you just wrote.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Victor Elizalde

Victor Elizalde

Software Engineer with a passion for sharing knowledge. Also, sports lover, musician, gamer, and a tremendous food fanatic.