berserk.org

berserk.org header image

Readable? Maintainable? Sexy?

August 2nd, 2006 · No Comments

Recently at work we’ve started up a “book club” of sorts (I’ll take the blame for it). The idea is that we cooperatively come up with material to review and then discuss it once a week to see how it can perhaps fit in to making us better.

I’m hoping it’s going over as well as I’m thinking it is (which is to say fairly well). I’m also hoping that the other developers aren’t secretly saying this is some stupid shit behind my back.

I’m just trying to find ways to keep us all interested, motivated, and most importantly keep rust from forming on our skillset/careers.

Anyway, one of the books we’re going over is McConnell’s latest Code Complete book. One of the topics from last week or so was the idea of readability and the concept of “Software is written once, but read often”.

I’m not sure where I got it from (I have my ideas), but I really like things such as:

if ( gatekeeper.getPermissionManager().getUserPermission() == Permission.READ_ONLY ) {

However attractive (or unattractive) that may seem to you, the argument would be that this:

PermissionManager pm = gatekeeper.getPermissionManager();
UserPermission up = pm.getUserPermission();

if ( up == Permission.READ_ONLY ){

would be more readable. And honestly, I’d have to say that is a correct statement.

It bums me out, really. But I’m cool with going along with it, and besides I can write personal code however I see fit.

Where this really leads me though, is I’m currently digging in to the .NET 2.0 framework code (huge props to Denis Bauer’s Disassembler) researching an assumption/theory about the new FileUpload component. My current path lead me to the HttpRawUploadedContent.WriteBytes method. There’s a terribly attractive line in there that looks like this:


byte[] buffer1 = new byte[(num2 > this._fileThreshold) ? this._fileThreshold : num2];

Looks good doesn’t it?

However, there’s that readable itch there in the back of my head saying “Geez, shouldn’t we break that out?”. I suppose the otherside (we’ll call him the “evil Cameron”) is saying “Come on, if the framework developers are doing it, why not”

You be the judge. I know it isn’t as readable. I know it isn’t as maintainable. But me I still prefer it.

Tags: code