Clean Code: why the shape of your code is a sin.

Last Saturday, instead of trying to see if there is any new SNL, I tried reading “Clean Code” again to find a solution for some codes I’m working on.

And of course, after a few hours, I found myself on YouTube (well somehow everybody does that, right?!) – watching Robert C. Martin: “Clean Code”. I’ve read his book, but this is the first time I see him speaking about it – and really loved the way he explained and addressed the points with such a good sense of humor.

At 1:00:24 into his talk, I found my “LOL” moment when he drew the shape for one of the functions he wrote in 1988, the function call “gi()” (graphic interpreter) that had ~3K line of codes.

And this is the shape of the code (well, sort of)

And look, have you ever recognize your code directly by looking at its shape? Ah, this routine looks really familiar, and that class and interface do ring some bell, oh the package name is so near and dear. 

We all have such moments, right? You once have written this type of function that only you or a handful of other engineers would understand it.

Looking at the shape of the function, your subconscious minds tell you: “Ah, calm down, you are at home, Sweetheart! That is the valley of If, here is the plateau of Switches and there is the river of Try…Catch. “.

You are safe because you see a familiar shape.

But to some other people, their minds are screaming: “Oh no, in that jungle of curly brackets the NullPointerException predator might be lurking, and in this maze of Init and nested loop, IndexOutOfBound trap is waiting for me”.

I can’t stop blowing some more air out of my nose while thinking about that. I did commit that sin – but you should not.

The talk is pretty funny and still informative, check it out and come back tell me if you agree to his jokes.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.