Monday, April 12, 2010

But, Eclipse makes it easy...

Charles Petzold has nice article titled Does Visual Studio Rot the Mind?. I was thinking about this article when doing a code review and frequently getting the excuse that the awful code was ok because "Eclipse makes it easy." The following snippet shows some of the problems:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package example;

import java.util.List;
import scala.actors.threadpool.Arrays;

/**
 * Immutable class for ...
 */
public class Example {
    private List<String> mData;
    private int mCount;
    
    public Example(String[] data, int count) {
        mData = Arrays.asList(data);
        mCount = count;
    }

    public String[] getmData() {
        return mData.toArray(new String[mData.size()]);
    }

    public void setmData(String[] mData) {
        this.mData = Arrays.asList(mData);
    }

    public int getmCount() {
        return mCount;
    }

    public void setmCount(int mCount) {
        this.mCount = mCount;
    }
}
Here is a brief look at some of the questions and responses.
  • Why do the accessor/mutator method names have the "m" prefix (by convention our code uses a prefix of "m" on member variable names, but it shouldn't be reflected on the accessor methods)?
    Eclipse generated the setters/getters. It makes it easy to generate them this way.
  • The comments say the class is immutable, why are there mutator methods?
    Eclipse generated the setters/getters.
  • The class is not immutable.
    Then why would Eclipse generate the setters?
  • Why are you using scala.actors.threadpool.Arrays instead of java.util.Arrays?
    Eclipse generated the imports.
It was clear from his answers that he barely looked at the actual code. Eclipse enabled him to cobble together some crap that compiled without really knowing what he was doing. This is not really the problem with the IDE, idiots can write code without the aid of an IDE. What really surprised me is another senior developer on the team supposedly reviewed the code and found nothing wrong. When I asked what he checked the reply was "I brought it up in Eclipse and didn't see any warnings or errors flagged on the code."

No comments:

Post a Comment