Code Smell

The first thing to recognises is that all code smells, it might sweet or foul, code smell is not a sign of a bad programmer. We all neglect code, copy it thoughtlessly and generally neglect some code. The secret

Chains: Long sequences of similar things, properties or methods suggest hidden dependency, c.f Single Responsibility.

Comments: In general you are writing comments for programmers perhaps even yourself, people not machine even with JavaDoc the end target of the comments is people. Comments that rigorously describe the code are pointless. The comments tell you the What and the Why and code the How.

Complexity: Keep logical complexity low.

Dead Code:

Deceptive Names: Class, method or property names that deceive of miss lead.

Duplicated code: Simply put don't repeat Yourself.

Embedded Types in names: Abstract the Type, Telephone.

Large 'God' Classes: All Class should have a single responsibility.

Long Method: Long method are a sign of complexity, the longer the method the worse the smell.

Long Parameter: Long parameter list are another sign of complexity, the longer the list the worse the smell.

Opaque or nebulous names: If you cannot name something clearly, it's single responsibility is at risk.

Code is written for other programmers to read; it is fortuitously that machines can execute it.

Inconsistency nomenclature: Avoid

Dead Code: Ruthlessly remove unused/unneeded code.

Generality / Excessive Generality / Insufficient Generality / Speculative Generality:

Temporary Properties: Do you really need it?

Quirk / Oddball Solution / Macho coding: One Solution to each problem, the simplest to understand and maintain.

Feature Envy: Class or Methods that make extensive use of something else; consider if it is the correct place.

Man-In-The-Middle: Why does he exist?

Parallel Hierarchies of Inheritance: Somethings' Up.

All code smells, just make sure yours smell sweet :)

oo_java_code_smell.txt ยท Last modified: 2013/04/04 17:32 by Martin Spamer