May 23, 2006

Coding Horror: Code Smells

Eit utvalg av "code smells"...

Coding Horror: Code Smells: "the most important guideline is to watch for warning signs in your own code-- so called 'code smells'"
....
  • Comments: There's a fine line between comments that illuminate and comments that obscure. .... Do they explain "why" and not "what"?

  • Long Method
    Sometimes length is justified, but all things being equal, a shorter method is easier to read, easier to understand, and easier to troubleshoot. ....

  • Long Parameter List
    The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.

  • Duplicated code
    Duplicated code is the bane of software development ....

  • Large Class
    Large classes, like long methods, are difficult to read, understand, and troubleshoot. Does the class contain too many responsibilities? ....

  • Type Embedded in Name
    Avoid placing types in method names ....

  • Uncommunicative Name
    Does the name of the method succinctly describe exactly what that method does? If not, rename it or rewrite it. ....

  • Dead Code
    Ruthlessly delete code that isn't being used. That's why we have source control systems.

  • Speculative Generality
    Write code to solve today's problems, and worry about tomorrow's problems when they actually materialize. Everyone loses in the "what if.." school of design. You (Probably) Aren't Gonna Need It.

  • Temporary Field
    Watch out for objects that contain a lot of optional or unnecessary fields. If you're passing an object as a parameter to a method, make sure that you're using all of it and not cherry-picking single fields. ....

  • Shotgun Surgery
    A change in one class requires cascading changes in several related classes. Consider revamping your design so that the change is limited to a single class.

No comments: