Jump to content

best practices


niche

Recommended Posts

which is best practices:echo '<input type="hidden" name="' . $clistknum . '-' . $id . '" value="' . $price . '" />'; orecho '<input type="hidden" name="' . $clistknum . "-" . $id . '" value="' . $price . '" />';why (or does it really matter)?

Link to comment
Share on other sites

In your case, I'd write it as

echo "<input type='hidden' name='{$clistknum}-{$id}' value='{$price}' />";

Assuming single quotes in the output XHTML doesn't bother you. Concatenation itself is a larger bottleneck than quotes... well... it's still a very marginally smaller one, so yeah... it doesn't really matter.

Link to comment
Share on other sites

Will no one make the argument for whichever style is easier to read? In this case, I can read boen's and get the gist of the output a lot more quickly than the concatenated version.Unless you plan to output 100,000 iterations of this string all at once, developer efficiency trumps program efficiency. IMHO.

Link to comment
Share on other sites

justsomeguy, boen_robot, Deirdre's Dad, thank-you very much for your help. As usual, I received unexpected benefits from each post.Niche

Link to comment
Share on other sites

Will no one make the argument for whichever style is easier to read? In this case, I can read boen's and get the gist of the output a lot more quickly than the concatenated version.
I think that depends more on the syntax highlighting. In plain black 'n white text boen's code is indeed easier to read, however, with the highlighting that my editor uses, it's easier for me to read the concatenated version:echo "<input type='hidden' name='{$clistknum}-{$id}' value='{$price}' />";vsecho "<input type='hidden' name='".$clistknum."-".$id."' value='".$price."' />";My editor doesn't color variables inside strings, maybe other editors do, but mine doesn't so I usually write concatenated strings.
Link to comment
Share on other sites

I wasn't trying to take sides in any cosmic sense. :) Just saying that developer efficiency should be a consideration, whatever tool gets you there.In-house practices (not mentioned before) are also worthy of consideration. If you have to update someone else's code, and he doesn't do stuff the way the rest of the shop does, that's going to cut productivity.

Link to comment
Share on other sites

While we're back on this subject, what's the reference for use of curly brackets in this situation?Thanks

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...