topic: clean code

Clean code is critical to the work success of coders in the workplace. If a person gets a job as a junior coder and just writes spaghetti code in their new job they’ll just annoy every technical person on their team. If they start their career by being annoying then their jobs are less likely to last. We need to produce juniors who pay attention to detail and care about the quality of their code.

If a person only writes spaghetti code then they will waste a lot of time if they ever try to solve a juicy problem. Their code will be buggy and unmaintainable at best.

In testing this skill, samples of code will be shown to the students and they will need to say how the code can be cleaned up.

Concepts to understand

  • code should be DRY
  • remember the principle of KISS (google it folks)
  • file and folder structure and naming conventions
  • naming conventions within code files (variable names, function names, constants)
  • names that are meaningful - good code makes its intention clear partially by choosing good names. Correct parts of speech (nouns and verbs), correct use of plurals
  • short, single purpose functions
  • flat code is better than nested code
  • baby coders think that if they write fancy code then they are fancy people, senior coders know that simple, elegant code is the way to go.
  • consistency is important - inconsistent code leaves the team guessing and introduces bugs and frustration
  • proper use of comments. Comments should add clarity for coders. Comments should never just paraphrase code in English
  • cohesion: if a variable is only used in one place then put it in that one place
  • don’t leave rubbish lying around: if a variable, function or test doesn’t add value then it should not exist. Streamline your code
  • gitignore should be used effectively - don’t give us automatically generated files (logs, databases or anything similar)

All code written during this course should be clean code.

  • if you write code for one of your projects: make it clean
  • if you review someone else’s work: help them to make it clean

RAW CONTENT URL