Fredrik Håård is a partner and specialist at Softhouse Consulting as well as co-founder and head developer at Visual Units, a Swedish company creating support tools for logistics. Fredrik is a DZone MVB and is not an employee of DZone and has posted 21 posts at DZone. You can read more from them at their website. View Full User Profile

Dare to Show Your Code

  • submit to reddit

My name is Fredrik, and sometimes I write code I’m not that proud of.

A friend of mine started on a Python project recently, and when I asked him to put it up on Bitbucket his response was an immediate and not-quite-mock “But then people will see my code!”. I believe this fear of showing one’s code is common, and I believe that it is a problem. Not so much for open source, or anything like that, but for the individual - it suggests a belief that your code isn’t good enough, that other people’s code is better, and/or that offering my code up for others to see will lead to rejection and ridicule. I know I was wary before suggesting a patch to Python, because I feared it was not good enough (it was, but the tests weren’t - nobody was mean in telling me they needed work to conform). I had over ten repositories at Bitbucket before I open sourced the first one, and I spent too much time worrying over the autohook source before daring to make it public... for no good reason at all.

Sometimes I’m not proud of my code; I was in a hurry, I was new to the tools or the domain, I was lazy, I did not know better at the time, there were customer demands I could not fulfill in any other way, or any other reason or excuse. Sometimes somebody tells me I should clean up my code - and that is good. Having others critique your code is one of the best ways of getting better, and knowing that others will look at your code will make you (at least it makes me) write better code. This is why code review is such a powerful tool - even if the reviews seldom find serious errors, people tend to write better code when they know somebody will read it right now, as opposed to that someone will be forced to read it when maintaining the code base some time in the future.

Added to this is, as much as we feel bad when showing our own code, so does everybody else, from time to time. Not all code will be perfect - I’d argue that if we spent the time to make all code perfect, we’d never get anything done. Besides, not everyone will agree on what perfect code entails, so it’s a fools errand - someone will always think there are things about your code that are imperfect. And that’s OK. Showing off my code online (some of it really ugly, like the Blaag source code) has netted me all of two immature flames, but also some clever insights, pull requests with bug fixes, and in one case even someone to discuss the code with (thanks Martijn!).

Published at DZone with permission of Fredrik Håård, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Hussachai Purip... replied on Wed, 2012/03/07 - 7:05pm

Good job, Fredrik Håård.

Perfection is an ideal. There is no perfection in this world
but many people try to get close to it. My code is good
enough (for me) but never be the best because there are
so much codes out there that is far better than me.
And I never pround of my code because every time
I rewrite it, it's usually better than the old one.

This is my open sources:
Currently, I opened only my java code but I hope
I'll open my python code soon.

Christopher Gilbert replied on Thu, 2012/03/08 - 4:20pm

It's true.  Sometimes the most learning experience can come from when others review your code or force to you explain why you did something.

Yaron Levy replied on Sun, 2012/06/10 - 10:25am

Some of my code is ugly, rarely do I feel that anything I write is "beautiful", however, if you never have anyone else look at (read: critique) your code, how can you hope to improve? Sure, it's uncomfortable having someone look at your code, but would you rather wallow in bad code or be given a shot at getting better?
From time to time I'm able to stuff a sock in my ego and tie it to a chair and put my code out there for review and because of that, I've improved.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.