How to write clean code : a summary

November 1, 2012 at 9:54 am (Programming, Styles) (, , , , )

This is basically a summary from Clean code : A handbook of agile software craftsmanship written by Robert C. Martin. This is done as an assignment work which is targeted at making programming students to read books for themselves. If this violates any copyright laws please let me know, although i had used my opinion as possible.

You can find the original book at this amazon page.

Note: This blog article is still under construction.

Introduction

Names can talk for themselves

  • If a variable, class or method name needs a separate comment to identify itself, the name probably needs to change.
  • Names should not include misinformation. For example, a grouped set of subscribers should not be identified as ‘subscriber_list’ if it’s not a list.
  • Names should not look similar at the first sight, as people who are reading code often don’t read the full name.
  • Avoid using l and O in small variable names as it could be easily misread for 1 and 0 ( one and zero).
  • Do not use misspelling as a tool to create new names (ex: listenToAdapter, listenToAdaptor).
  • Use pronounceable names as possible, which could be easy when at the code reviews.
  • Remove obvious redundant words from the names like the, a , an, class, var.
  • Names should be unique enough to easily search, if needed. This is strictly needed if the scope is high.
  • No need to shorten names as we have more advanced languages and GUI tools now days.
  • Use nouns (or nouns which can be used as verbs) for class names and verbs for method names.
  • Any name should be generally understood by any programmer of any demographics.
  • Use one word for a similar concept throughout the code base.

Permalink 1 Comment