A good programmer always thinks like a tester and a user
Alright, in this new series of Smart Coding, I am going to point out exact problems and how smart coders should code it.
So here is a perfect example of a good and bad coder.
In this live page below, we have Major Categories and Minor Categories drop down lists. When you select a Major Category, the minor categories belonging to that major category will be loaded.

If you can see from the right top corner, there is AJAX is being used and I see the Loading… message for a long time. That is because on DropDown item changed event, the code is probably trying to load matching minor categories.
So what happens when site is slow or database response is slow?
I am waiting and waiting and waiting. This is what happens. That is a perfect example of Bad Code and Bad Coder.
Being a smart code, what you could do is, load both Major Categories and Minor Categories at once and filter Minor Categories in-memory based on the selected Major Category. That will take no time to load the data.
So, major categories and minor categories usually do not chanage a lot. It makes perfect sense to cache them in memory. It might not be a bad idea to store them in Application State. You can even dump all data in a single DataSet with two DataTables. Based on the major category selected, you can just filter the data using a DataView or use Row Filter on DataTable.
A good programmer always thinks like a tester and a user.
Cheers!

Suthish NairPosted May 25, 2016, 6:08 AM
Old blog, but still a good read and important for coders..
Amatya AgyeyPosted May 24, 2016, 6:08 AM
DeadLines and pressure makes the coder to focus more on functionality rather than aspects.. :(
urmila naikPosted Aug 9, 2012, 4:06 AM
very nice and true:)
urmila naikPosted Aug 9, 2012, 4:06 AM
very nice and true:)
urmila naikPosted Aug 9, 2012, 4:06 AM
very nice and true:)
Vilas GitePosted Jul 13, 2011, 9:15 AM
Mahesh sir, nice explanation specially, "Requirements are broken into smaller modules", this statement really helpful for me future... :)
Suthish NairPosted Jul 13, 2011, 4:18 AM
This bad coder belongs to your team?
Mahesh ChandPosted Jul 12, 2011, 3:56 PM
Good point Amit. However, there is nothing like so called "design phase" these days. The way software development is working today, whole SDLC is becoming obsolete. You get requirements direct and start coding. At least, this is the trend in US. No time for design really. Requirements are broken into smaller modules. The purpose of this post is, we as a coder, shall be more responsible because we are the one who are writing the code and designing user interfaces. Design is not really going to tell how to code.
Jaganathan BantheswaranPosted Jul 12, 2011, 1:07 AM
Very nice mahesh.... Two Mango with one Stone....
Amit ChoudharyPosted Jul 12, 2011, 1:03 AM
Hi Mahesh, You are absolutely right here. But i think we should'nt blame only the code/coder. When we talk about performance and scalability of application then these things should consider from the time when it was in designing phase. but usually what we do is develop the application and then we look for performance and scalablility and that need more efforts than required. Atlast since it involved in development phase then everybody stands up to blame the CODER. I'll say it was a miss not considering these things in designing phase. Thanks.