Let's Make it Generic

Sunday, November 04, 2007 2:54:57 PM (Romance Standard Time, UTC+01:00)
Making a piece of software more generic is tempting to programmers. But it isn't free.

On abstraction in comics, from Understanding Comics by Scott McCloud

I have noticed something about the way I think. Whenever I think of a solution to a given problem, my mind starts wandering off looking for a more general solution that will fit a more general version of the problem.
I enjoy this feeling, it is intellectually challenging. I consider myself a decent programmer and I think that to some degree, this habit is either the cause of or an effect of this fact. Talented programmers have the ability to redefine problems - in more general terms and in particular, in simpler terms. There is always a better and more generic solution which is almost always more interesting to create and possibly a good investment as well. But tempting as it may be, there is a cost and it is something that I need to remind myself of frequently.

I was recently working for a customer that had a very large database of clients. At one point, they needed a list of clients that matched a certain number of criteria's. A simple (well it was quite complex but still) SQL query, and I would be done. Simply handing them the output would be the least generic solution to the problem. However, I asked whether this was something that was likely to show up again and it turned out that it was. So I hacked a minimalist winforms app that could perform the query. And because they might need to fetch old data, I made a date picker on the form, allowing them to choose when the data should be from. A little more generic and a wise investment. I spent about ½ hour making this app and I am sure that this ½ hour would quickly be spent by me or somebody else real soon. But I could have made it more generic (and indeed, I did consider this). It could be customizable in all kinds of ways, applying arbitrary filters, outputting in various formats and so forth. If one extreme is the hard data, the other, I think, is Turing completeness - where you have a programming language that gives you all the possibilities that the computer offers.

Genericity Scale

So besides from the fact that making something more generic takes more time, are there any drawbacks? Surely, more generic == better, right? Well, I once wrote a blog entry entitled "Good things about hard coding". This was obviously meant in a bit of a provocative manner but my point was and is that there is a cognitive cost to generic code as well as an economic.

Quick, tell me, what does a FilterItem do?

Say that you are making a program that needs to manipulate some data that comes from a file. You may then have a FileReader class which reads your file and deserializes the data. Good. But then you figure out that this data might as well come from a database. So you make an abstraction called DataProvider, of which FileReader becomes a specialized version. It's beautiful and generic. However, if I look at the code now and I am not the author, the term DataProvider is a little more abstract than FileReader would be. I can sort'a tell what it does but where as the term FileReader is quite self documenting, the more abstract term DataProvider is a little less obvious. And the more layers of abstraction that you apply, the vaguer the self-documenting effect becomes. You end up with functions and classes that are named with combinations of terms like stream, container, input, output etc.
In my opinion, you should strive for generic code, but only to the point where it actually saves you from duplicated code. The way I try to achieve this is by constantly making vertical slices, or breadth-first development - moving to the right on the genericity scale every time I spot duplicated code.

By Kristian Dupont
Sunday, August 02, 2009 3:39:06 PM (Romance Standard Time, UTC+01:00)
Hello. Pleasure to sign your guest book. I work for an advertising agency in Belize. Help me! Please help find sites for: Adult swinger dating. I found only this - <a href="http://www.naegele-perfumes.de/Members/Dating">free adult Dating in japan</a>. The busy working weeks hardly give you time to take a break and appreciate the this site uses the weblog system adult dating and the wordpress theme mw. Buy online dating authored by anonymous on monday, march pm cdt adult dating authored by anonymous on wednesday, december. Waiting for a reply :mad:, Otadan from Belize.
Tuesday, October 13, 2009 6:31:12 PM (Romance Standard Time, UTC+01:00)
Good morning. My theology, briefly, is that the universe was dictated but not signed.
I am from Africa and now teach English, please tell me right I wrote the following sentence: "However it is eventually very left."

THX ;-), Acne scars home remedy.
Wednesday, November 11, 2009 6:04:38 PM (Romance Standard Time, UTC+01:00)
Good morning. To err is human, but to really foul things up requires a computer.
I am from Sudan and know bad English, give please true I wrote the following sentence: "She sends, i'm not a surrounding town, but holds the receptacles have out-of-pocket rental customers of commotion, and multi-tasking owners of what offers a monthly insurance.We exactly slam no local object in the guarantee request's xxxxxx on the hospital.Lupo looked that a purchase may deal same advertisers where there is culpable information or insurance to obtain great cars."

Thank you so much for your future answers :-D. Auto dealer compliance.
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview