Saturday, January 21, 2017

Portable code smells list ;-)

Here list of things which are for me code smells, and short description of things I'm looking for during code review when I'm finding such things:

  • protected - why this should be visible for subclasses but not rest of the world? Sometimes it make sense, but usually means that we are leaking some elements of implementation, maybe default will be better? You will have access in given package, but this will stay here,
  • fileds other than private - why such field exists? Somebody may modify this field and whole code may start to do strange things...,
  • extends - wasn't it used here only for keeping 1 copy of code? Is subclass more specialized case of superclass?
  • abstract - why this class exists? Isn't class hierarchy too high?
  • big class hierarchy - are all subclasses needed? Are those more specialized than superclasses?
  • setting capacity in collections - why its here? If this is HashMap do we take under consideration threshold? Premature optimization? Can be negative?
  • casting - where we are loosing type information?
  • long names - one letter is too little, 12 or more letters are probably far too much ;-)
  • I at the front of interface name - this is Java!
Usually when I'm seeing those code smells this means that code isn't healthy, and will make a lot of problems latter.
Of course if author is able to explain why given thing was used I'm OK, this is not religion ;-)

Similar postsbeta
How to get negative number from size() in LinkedList in Java? ;-)
My road to automation ;-)
Coding time means often waiting/reading time ;-)
Borders, immigrants and so on
Android vs iOS

No comments:

Post a Comment