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!).