Code Quality
  Posted February 03, 2003    PermaLink    Comments (2)  

These code quality metrics proviced by PMD and Eclipse are quite nice, it points out all sort of strange things. But there are some thing it doesn't get...

For example I came across a class written by another developer (not sure who at this point). The first thing that caught my attention about that class is the incessent use of this. to refer to local fields. And he would never use a class name to refer to another static field, which is what tripped eclipse to check. After reviewing the class and parent class in question I came across a doozie... all of the methonds and fields were static, except that the fields were initilized by a non-static constructor! It's not like it's a forced option, since you can use static { ... } to initilize static fields. There are just some stupid patterns that you can never imagine until you see them.

PMD definatly needs a "StaticFieldReference" rule, perhaps they also need a "StaticInitInConstructor" rule, where it barks if you set the value of a static field in the same class inside the constructor of a class. Manipulation is ok.

Trackback URL
  TrackBack URL for this entry:
Date:February 4, 2003 09:41 AM

Something wrong with using 'this' for all local field references? I always do this - a habit picked up from Python, I guess, but I son't see that it does any harm. Quite the opposite, I find.

Name:Danno Ferrin
Date:February 4, 2003 03:53 PM

You're right in one regard, it's not in and of itself evil. I just come form the schools of thought that variable names shouldn't conflict and that you sohuld be as expressive as necissary, but no more. So this means that 'this' is superfluous except in cases where names conflict, and then we can go to my first school of thought and conclude you are doing somehting wrong. Out of visibility variable names are just asking for coding errors IMHO.

But Pyhton's OO methodology remindes me of doing OO in C: no magically hidden steps (which can be good or bad depending on your needs).

Post Comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Remember me?

Email Address: