| Re: Why sprintf? |
by Brad on 2004/7/3 17:50:35 To be clear... I wasn't saying my preference was to use sprintf(). At this time I don't have much of a preference although your two examples do look circus seal enticing. I was just saying that in general, maintainability is very important and shouldn't be overriden by speed issues alone. I think you *fully* agree with me, Dave.
|
| Re: Why sprintf? |
| by Dave_L on 2004/7/3 13:35:28 I mostly agree with Brad. Maintainability is very important. But a second can be a significant delay for a web page, especially in combination with delays caused by other factors. Howver, I'm sure that a single sprintf takes much less than a second. Personally, I try to avoid using sprintf simply to achieve string concatenation. Here's my preferred way of doing queries: Example 1: le="color: #000000"><?php $challenges_table = $xoopsDB->prefix('chess_challenges'); $result = $xoopsDB->query("SELECT player1_uid FROM $challenges_table WHERE challenge_id = '$challenge_id'"); If the query is long, I break it up into separate lines to make it more readable. Example 2: le="color: #000000"><?php $challenges_table = $xoopsDB->prefix('chess_challenges'); $result = $xoopsDB->query(trim(" SELECT game_type, fen, color_option, player1_uid, player2_uid, UNIX_TIMESTAMP(create_date) as create_date FROM $challenges_table WHERE challenge_id = '$challenge_id' ")); (In XOOPS 2.0.7, the trim() isn't needed, since XoopsMySQLDatabaseProxy::query was modified to strip leading whitespace.) |
| Re: Why sprintf? |
| by sottwell on 2004/7/3 13:28:28 Just wanted to know if there was some reason why I should use it, if I don't want to. Thanks. |
| Re: Why sprintf? |
| by Brad on 2004/7/3 12:45:24 Quote: Dave_L wrote: To add to that... Slower isn't always a bad thing. Code maintainability is just as important as absolute speed. If it was slower by, say, more than a second, then it could be an issue. If we're talking a difference of less than a second... Not an issue. |
| Re: Why sprintf? |
| by Dave_L on 2004/7/3 12:05:11 That's correct. sprintf is slower than concatenation. |