Twelve Ways To Make Code Smell Less By Venkat Subramaniam

We all have seen our share of bad code and some really good code as well. What are some of the common anti patterns that seem to be recurring over and over in code that sucks? By learning about these code smells and avoiding them, we can greatly help make our code better. Come to this talk to learn about some common code smell and how to improve the quality of code.


Venkat Subramaniam

Why should we care about code quality?

  • We can’t be agile if the quality of code is realy poor
  • Code is how we tell our collegues how we feel about them

What is code code quality?

The quality of code is inversely proportional to how long it takes to understand it

12 ways to make code smell less…

  • 12 Schedule time to lower technical dept
    • Ward Cunningham
    • Technical dept will grow without doing anything. Eg older version of java
    • low quality is not technical dep
    • Linda Rising (a freeway filed with cars is a parking lot) if you dont have slack time you will never be able to innovate
    • Guns, Germs and Steel by Jared Diamond
  • 11 Favor high cohesion
    • Do one thing and one thing well
    • High cohesion == low cyclomatic complexity
    • Takes a bit more time place stuff in the right place but maintaining it
  • 10 Favor loose Coupling
    • The new reserved word promotes tight coupling
    • perceived dependencies are not necessarily actual dependencies
  • 09 Program with Intention
    • When I wrote this, only god and I knew this code. Now god only knows.
    • Beck’s rule if design
      • Passes tests
      • Reveals intention
      • No duplication
      • Fewer elements
  • 08 Avoid primitive obsession
    • Am I the chosen one?
      • if yes then do it
      • if no someone else already wrote it
    • Imperative code is packed with accidental complexity
    • It’s code like this that prematurely turns programmers into managers
    • A good code should read like a story not like a puzzle
    • Declarative in style leads to functional programming
  • 07 Prefer clear code over clever code
    • We tend to make code clever because it feels really good
    • Programs must be written to read and only incidentally for macheies to execute
    • 10% of the time we write ugly ode for performance reasons and the other 90% of the time to stay consistend
  • 06 Apply Zinsser’s Principle on Writing
    • ‘On Writing Well’ The classin Guide to writing non Fiction
    • Hard writing makes easy reading and easy writing makes for hard reading.
      • Simplicity
      • Clarity
      • Brevity
      • Humanity
  • 05 Comment why, not what
    • Good code is like a good joke. If you dont get it dont explain it.
  • 04 Avoid Long Methods - Apply SLAP
    • How long is long?
    • Turns out long is not about length of code, but level of abstraction.
    • Code focus on single level of abstraction
    • SLAP > Single Level Abstraction Principle
  • 03 Give Good names to variables
    • Programmer: one who van name their children quite easily but has a hard time naming variables
    • program archeologist. We have opinions about the what we think the original progammer ment and another program archeologist has another opinion about it.
  • 02 Do tactical code review
    • Never tell what is wrong with the code but always tell what can be done better.
    • Fix a bug by writing a test for it
  • 01 Reduce state & State mutation
    • Reluctantly allow state to exist.
    • Mutability needs company… bugs

Great talk … thanks Venkat!