Jochem Maas wrote:
hi Alexander,
interesting question regarding 'safety' v. readability v. speed - I'm
sure you'll get different views depending on who you ask.
Here is my take:
Thank you Jochem! :)
I rate speed as the least important issue - you can alway use a faster
machine, get some more RAM etc if you really need a quick speed fix.
making the code faster is the last exercise I do in any given project,
and I almost always choose readability/'safety' over speed
I know what you mean and also agree generally, however I am nevertheless
usually trying to have the code as optimised as possible. If I just knew
better Assembler I would probably code all my webstuff in .asm files ;D.
Seriously, I prefer to have code as compact, small, efficient and
optimised as possible a personal thing I guess.
This is a compromise - can't imagine why anyone would choose this one.
Well, perhaps because it is a compromise ;). Its readability is much
better than with string concatenation however its performance drop is
still not that bad because its a native function.
YEAH!
indeed its the slowest. but its so much more readable and you know its
alot more maintainable (you don't have to change the escaping,
sprintf'ing strategy in 100 places.).
Its safer too because there is no chance of forgetting to escape the sql
args.
That were also exactly my reasons why I fancied it.
Imagine you have a highly dynamic page that does 50 queries (using the
3rd technique you proposed), I would guesstimate that refactoring the
code to do 2-3 less queries per request would get just as much speed
increase (if not more) than by refactoring the code to use the 1st
technique on all 50 queries
Thats probably correct.
(granted you could refactor both but heh
there are other things to do than code PHP 24/7 ;-)
I know, I know ;)
And if speed really is a big issue - you may need to look into writing
part of you application logic as a PHP extension (i.e. in C which is way
faster anyway you cut it.)
Well, my worries now dont go that far :)
Again, thanks very much for sharing your thoughts with me.
Alexander
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php