395
edits
Philosopher (talk | contribs) m (<syntaxhighlight> and tabulations and style) |
Philosopher (talk | contribs) m (and one more :) |
||
| Line 257: | Line 257: | ||
While this is not a very complex or huge block of code, it is an excellent example for very good naming conventions used already, because the consistency of naming variables and functions can pay off easily here, with just some very small changes, you can already reduce the whole thing to a hash lookup like this: | While this is not a very complex or huge block of code, it is an excellent example for very good naming conventions used already, because the consistency of naming variables and functions can pay off easily here, with just some very small changes, you can already reduce the whole thing to a hash lookup like this: | ||
<syntaxhighlight lang="php"> | |||
weather_tiles["set_"~code~"_tile"](); # naming convention | |||
</syntaxhighlight> | |||
This would dynamically concatenate a key consisting of "set_" + code + "_title" into the hash named weather_tiles, and then call the function that is returned from the hash lookup. | This would dynamically concatenate a key consisting of "set_" + code + "_title" into the hash named weather_tiles, and then call the function that is returned from the hash lookup. | ||
edits