Code confessions, if you may… You grow as a programmer over time, and looking back at some piece of code, you’ve written a while ago would make you uneasy. Has this happened to you?
I was going through my old code and found this:
jQuery(jQuery('*', this).filter('input[type=text],textarea')[0]).focus();
Which is equivalent of :
$('input[type=text],textarea', this).first().focus();
So, what according to you is a really bad piece of code you’ve written a while ago, why was it bad, and what are the lessons that you’ve learnt?
Well, well. I guess I need to write a book on this. Trust me, whatever piece of code I've written over my initial days, it was nothing but horrible! Let me dig through my old code and give you some samples!
Not now. Those days are gone and I can see the improvement myself. I;m not cursing myself these days. In fact, there are certain code blocks, which I see after a while and I praise myself. :D Sounds funny, but true. It is more like, the number of mistakes we make becomes lesser with experience!
Lorefnon
Open Web Enthusiast
I remember having found this in a codebase I inherited.
There was an an unindexed query on a join of three large tables which would generate a resultset of hundred rows. But thanks to our A/B testing setup - only about 40% of users would be shown the resultset - the person who setup the test took the most convenient route and added an if condition in the view. Job done. The query would of course be executed for all users.
The people who were being shown the resultset, were being shown only 5 entries of those hundred. Rest was hidden - by css - on the client side. At some point there used to be a "See More" button to expand the list, but later that button was changed to direct users to different page where a more detailed list was shown.
Moral: Adopting the path of minimal change is a dangerous policy.