hi at all,first i want to say sorry for my english :)i have one dtd-file and some xml-files based on...
By meglepetes
XML 2005 program additions/ updates announced-- discounts availableuntil October 10 -- Low airfares ...
By melledge
M,L7_S97@%?#^D-:4=>W9[.A_4W`LD/-L#:1+A5[Q?)L*L@G[%ZN$1L-&_4DQMSK:G4!@#&D!5@!O*#W7X&HZ...
By hbb
hi, i need to write simple c program that work with MYSQLAPI .it'svery simple to do, i have jus...
By f4bi0
Should I choose Data Report or Crystal Reports for my applications (local and remote) and why?Thanks...
By lvzito, 3 Comments
PGP SIGNED MESSAGEHash: SHA1NotDashEscaped: You need GnuPG to verify this messageThe call for papers...
By gregsabinomullane, 1 Comments
Riddle me this.I've built a site on a Linux server that's running Apache. I'm trying...
By ccooper, 2 Comments
Hi all,can any one give me good examples of bcnf, 4nf, 5nf &denormalization...
By sam, 2 Comments
I have a project that requires using a trigger to send email (via Great Plains Dynamics Accounting)....
By dougjohnson3, 3 Comments
1 and 3 can be catered with a constant instead. Magic numbers/globals are really bad and I would actually order them with 2 first if I was forced to use one option and I could not use constants. Globals never ever ever need to be used, especially for things that do not change after being set. A config object passed around is better as that can be locked after setting.
2) You can use a static array in a function/method call to cache repeated lookups per page request. If your database is set up with query caching the results to the lookups will be cached anyway so it is a negligable thing you are trying to avoid on such a small static table. Even without query caching it's still does not rate below using globals.
//Static lookup caching function
function CachingLookUp( $id , $dummy_value = '' )
{
static $index = array();
if( !isset( $index[ $id ] ) )
{
//Set with value from db or whatever
$index[ $id ] = $dummy_value;
}
else
{
print_r( $index );
}
}
CachingLookUp( 1 , "ancd" );
CachingLookUp( 1 );
CachingLookUp( 2 , "dbdbdbd" );
CachingLookUp( 2 );
The thing that comes to mind is a multi national/multi language system should try to be completely agnostic. Though if you do decide to do special cases( for us and canada ) it should be abstracted from the main process of page creation.
eg.
//Special case lookup function
define( "COUNTRY_CAN" , 38 );
define( "COUNTRY_US" , 223 );
function SpecialLookUp( $id )
{
switch( $id )
{
case COUNTRY_CAN :
return "ca";
case COUNTRY_US :
return "us";
default :
return ;//do db lookup or whatever
}
}
The thing to do is not go down the premature optimisation route but look at what you are doing, see where you might need to optimise in the future and leave youself with an easy elegant way to do it.
http://en.wikipedia.org/wiki/Optimization_(computer_science)
"When to optimize" bit for more
mpb001 | Fri, 16 Nov 2007 01:41:00 GMT |
Thanks!
I have been trying to avoid using global values.
I may stick with the option 1) for now.
It will be easy to mass replace the codes ==223 with ==$usa_id, ==38 with ==$canada_id later on if I want to update to option 2).
And I can have a script to be included to the pages which the replacements will happen and assign the new $usa_id and $canada_id values in the included script.
blackhorse | Fri, 16 Nov 2007 01:42:00 GMT |