The use of placeholders should not be evaluated on a case-by-case basis, but instead on an overall basis. Understanding where placeholders can safely be avoided requires the same level of knowledge as knowing where 'strict' can be safely avoided. It is telling that nearly every Perl developer who has been lead on at least one project starts every file with use strict;.
The same goes for placeholders. It is a good habit. The query isn't using anything variable ... today. If you use placeholders, you have future-proofed your query. By not using placeholders, you have introduced a place where bugs can occur and you have to be more vigilant. I don't know about you, but if I can avoid having to be vigilant because a certain class of bugs simply cannot occur, I'm going to.
As for your example, if the snippet was part of a larger application, I would definitely say in a code review to use variables. There is no reason not to future-proof it.
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
| [reply] [d/l] |
I agree with using placeholders when there are variables in the query, but saying "sure, it's static today...but that doesn't mean it always will be" is like saying "Sure, your print statement doesn't need formatted output today, but someday it might. Therefore, always use printf." Planning for "someday" is an exercise in futility; code for what you need today and worry about tomorrow when it gets here.
thor
Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come
| [reply] |