Quote:
Originally Posted by Tickler
One little thing that I've seen many times because the programmers don't understand the data.
You quite often see coding that looks something like this with test arranged in order:
Code:
switch ($someField) {
case "A":
do_A();
break;
case "B":
do_B();
break;
case "C":
do_C();
break;
default:
doOtherThing();
}
But if condition "C" equals 90% of the time, you should do the test for "C" first.
Very simple concept, that has major performance issues when dealing with high volumes. I've even written code that modifies this testing code based on current data being used.
|
That's a good point. I've seen many programmers reply to that with simply "a fraction of a second isn't going to make a difference". How wrong they are if they work on anything large scale.
It's the same with database fields, a lot of people use the field default size. For a simple example, I've seen people who know the maximum character length of a username on a site is say 20 characters. They create field as varchar(255). Or they know they use 2-letter country codes, but instead of char(2) they use varchar(255). That starts to add up once you are talking a large site with heavy traffic and millions of records.