Wednesday, August 30, 2006

 

My code can beat up your kid's code


This afternoon, I coded this java statement:

infinitive = Verb.class.getMethod(stemMethodName,String.class).invoke(null,verbFormConstructedFrom).toString();

I'd like to say that I coded it spontaneously, that I'm a master of Java reflection, but it took an hour or so to get right. The problem was that I didn't realize that any method so invoked must be public. I'm used to C++ where you can assign private functions to pointers to members.

But that's not what this post is about. It's about needlessly complicated lines of code--like the one above. We programmers really do like to show off and one way to do that is to string together long sequences of object references without ever declaring a variable to assign them to. The code above would be much more readable like this:
Method method = Verb.class.getMethod(stemMethodName,String.class);
infinitive = (String)method.invoke(null,
verbFormConstructedFrom);
Much easier to understand, but a lot less fun as well. That said, during my consulting years, I often noticed that hard-core computer science programmers tend to write in succinct but obscure styles while business programmers tend to write in a more verbose, but simpler style. One style privileging self and the other, the Other .

I am more and more convinced that computer programming as writing and therefore as communication is constrained by socially constructed value systems, that the values of the programmer are evident in his or her code--indeed that it is impossible for it to be otherwise as the code is the programmer.

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?