Originally Posted by NogDog
A belated question/reply to this thread but I wanted to ask you something about the solution you provided.
Basically I am using what some people describe as an ungly case/switch method within my index.php gile to switch the title tags etc etc.
Your method looks nice and I wondered if there are any performance implications using a nested array?
I think you will find the performance neglible.
a switch/case & if/else will create code like
while an array system will reuse the comparison routine
compare AX, ConstantA
move ax, Data1
compare AX, ConstantB
move ax, Data2
Although the use of the array shortens the amount of code produced, it does have the slight overhead of the math to calculate the position of the next element. The code snippets are pseudo code, and very simplified, but it's just to give an idea of what is produced by the interpreter/compiler.
move AX, VariableA
MOV DX, ArrayConstant
move IX, 0
Compare [DX+IX], AX
For myself, I prefer using an array system. Because it keeps code more compact. When you been around for awhile and see if/else...switch/case statements hitting 30-50 blocks. and trying to fix/update the code becomes a chore.
My rule of thumb is never to use more than 3-5 if/else...switch/case statements. At this point consider using an array system.
New coders often find using arrays difficult so postpone learning them.
Anyways good luck on yer coding
Another good rule of thumb is to code for maintainability first, and worry about performance only if and when you find that you have to. (More often than not, your main performance bottlenecks will be the database, not your PHP code -- unless it's really, really awful ). That's not to say you shouldn't think about code efficiency at all, but I'd rather worry about saving hours of debugging versus microseconds of performance.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Great work. You all have given very valuable information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)