About

Why

Why should You care about Elegant Coding, hence elegant (clean) code? Here are a few reasons:

  • Be Professional
  • Write code fast and predictably
  • Make code easy to read for others and You in the future
  • Be Ethical and Proud of Your creations

One of our difficulties will be the maintenance of an appropriate discipline, so that we don’t lose track of what we are doing.

Alan Turing 1945

The software didn’t change much. Invariably in programming are Sequence, Selection, and Iteration. Every code consists of these three elements. Since the basis of programming doesn’t change for decades. It’s valuable to learn them.

How

Programmers are slow because they make a mess. They make a mess because they want to go fast. The only way to go fast is to go well.

Elegant, well-written, and clean code makes programming fast.

When making code work making a mess and it’s fine. What is not fine is leaving that mess afterward. Writing good code can be split into 3 parts:

  1. Create tests
  2. Making code work (pass tests)
  3. Cleaning the code (refactoring)
  4. Make sure that the code still works (tests still pass)

Tests are a great tool for points 1 and 3 that’s why it’s good to write them before writing any code and refactor them as any other code to keep them clean as well.

Doing only point number 1 leads to messy, poor-quality code and a slowdown in development.

What

Clean (elegant) code:

  • is elegant and efficient
  • dose one thing well
  • is simple and direct
  • reads like well-written prose
  • looks like it was written by someone who cares
  • turns out to be what you expected
  • is not surprising

Elegant Code is polite for the reader. It’s written like an article. It goes from a high level of abstraction to lower levels step by step.

The Craftsman’s Oath

proposed here by Robert “Uncle Bob” Martin

  1. I will not produce harmful code.
  2. The code that I produce will always be my best work. I will not knowingly allow code that is defective either in behavior or structure to accumulate.
  3. I will produce, with each release, a quick, sure, and repeatable proof that every element of the code works as it should.
  4. I will make frequent, small releases so that I do not impede the progress of others.
  5. I will fearlessly and relentlessly improve our work at every opportunity. I will never allow it to degrade.
  6. I will do all that I can to keep the productivity of myself, and others, as high as possible. I will do nothing that decreases that productivity.
  7. I will continuously ensure that others can cover for me and that I can cover for them.
  8. I will produce estimates that are honest both in magnitude and precision. I will not make promises without certainty.
  9. I will respect my fellow programmers for their ethics, standards, disciplines, and skill. No other attribute or characteristic will be a factor in my regard for my fellow programmers.
  10. I will never stop learning and improving my craft.

More about Elegant Coding at Elegant-Coding.com