Couple of month ago, after posting some comments about bad code on Twitter, my ex-work-mate Peter (greets to Oz) asked me to show it s.t. others can view and learn from it. I really like the idea and so, why not to start and post ugly, smelly code on my blog and you on your blog as well. I'm sure you have something to share ;)
The Idea......is to have a similarly structured blog post with in the title "Smelly Code:". Once published, the post should then be published on Twitter too, with a link to it including a "#smellycode" hashtag s.t. others can follow such posts easily.
For this purpose you may employ Twitterfeed and set an appropriate filter which does the job for you.
- Do not blame others. The scope is to learn and improve your own coding skills. So don't include any names, don't be rude etc...the usual stuff ;)
- The post should only contain real-world code, so it shouldn't include general hints, suggestions etc, but rather it should contain code you encountered during development or coded yourself. In order to not conflict with your company politics you may of course obfuscate things, change names etc or cut out irrelevant parts.
- Do show code!!
- For easy reading between different blogs, please conform to the post structure as shown below.
- Please do use some syntax highlighter to improve code readability ;) . Prettyprint and SyntaxHighlighter are some popular ones.
The StructureThe blog post should more or less have the following structure.
Optional small intro sentence to your post
Original, smelly code
This section should contain the original, smelly source code, appropriately highlighting the problem.
Objections and Comments
Do explain why the code is considered to be smelly. What are the potential problems, negative side-effects? May it become a problem later, during maintenance? ...
Describe a possible refactoring in order to avoid the mentioned problems and include appropriate code.
In the next days I'll publish the first of these posts. Keep up on Twitter ;)