Error: I'm afraid this is the first I've heard of a "txt" flavoured Blosxom. Try dropping the "/+txt" bit from the end of the URL.

Mon, 24 Sep 2007

Objects Considered Harmful
From time to time I feel a strong urge to write an article describing how object-oriented programming is bad. Well, this post is not a full analysis, just a simple example. I have tried to read some Java code (maybe I am becoming a masochist :-), and found this:

     * Get X position.
     * Shortcut for getPosition().getX();
     * @return X position
    public int getX() {
        return x;

It is nine lines (and nine more for Y) so that they can write something like this:

    myobj.getX() + myobj.getY();

instead of the following:

    myobj.x + myobj.y;

I wonder why some programming languages tend to attract people who like to write mid-layers. Java is probably the worst one, but also Python with its Zope and Plone mammoths, and Ruby with RoR are similar. Wrapping wrapped wrappers into the wrapper code. I have yet to see something like this in Perl (yet OOP is widely used in Perl). I think accessors and mutators are amongst the worst habits in OOP. Most often they are just like the above code - dummy wrappers for the class member variable. Maybe Java people have some sort of mighty IDE, which generates such a write-only garbage for them.

In a related news (related to the mid-layer problem), see this post about trying to use Ruby on Rails (another midlayer-happy framework).

Comming soon on your favourite flamebait channel: Wrapping SQL Database to Objects Considered Harmful. Stay tuned. #