software engineering
Software engineering, patterns, programming.







Subscribe to "software engineering" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.
 

 

Friday, October 15, 2004
 

Funny story at work today about several domain objects in our webapp codebase with extremely verbose toString() methods. You know, you've seen these before:

public class Frob {
    public String toString() {
        StringBuffer buf = new StringBuffer();
        buf.append(getClass().getName()).append(":");
        buf.append("foo=").append(getFoo()).append(",");
        buf.append("bar=").append(getBar()).append(",");
        buf.append("baz=").append(getBaz());
        return buf.toString();
    }
}

Somehow, these toString() methods are supposed to be handy. The next logical step of course is to litter your code with logger statements that dump objects out to the console:

public void doIt(Frob f) {
    logger.fine("Value of frob in doIt: " + f);
}

As it happens, we use a proprietary JDO implementation for persistence in our webapp, which works great most of the time, but in this case the "magic" of bytecode enhancement, transparent persistence, fetch groups and lazy-loading of fields really bit us, because it turned out that there were objects not unlike the above which not only printed out all values of their own fields but all children objects as well. A little while later after iterating through a couple dozen such objects and dumping them out with logger statements, the code had fired some 22,000 select statements at the database in the course of a single web request.

I just may never write another single logging statement or toString() method in my career.


5:29:13 PM    comment []


Click here to visit the Radio UserLand website. © Copyright 2005 Nick Sieger.
Last update: 2/3/05; 11:00:59 PM.
This theme is based on the SoundWaves (blue) Manila theme.
October 2004
Sun Mon Tue Wed Thu Fri Sat
          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            
Sep   Nov