When coding (in any language), do you put more points in code efficiency or code readability / understandability?
This question came up as I am working on a piece of code (in PHP) involving foreac() and if() statements.
Attached are two really simplified codes.
First code is what I had at the beginning, where I have if() statement enclosing foreach()
The reason for this is to reduce the amount of if() comparisons with each loop.
Second code is the revised code, where the if() statement is inside foreach() loop.
This code is much easier to read and with less code repetition. But the downside is the if() grows up as the loop grows.
Which do you prefer?
Which is the better approach in your opinion?
I know for small amount of loops, second approach may be favorable.
But think about 100 loops that got executed each time a visitor refresh a page. It goes up quite fast with that.
-stndn.
This question came up as I am working on a piece of code (in PHP) involving foreac() and if() statements.
Attached are two really simplified codes.
First code is what I had at the beginning, where I have if() statement enclosing foreach()
The reason for this is to reduce the amount of if() comparisons with each loop.
Second code is the revised code, where the if() statement is inside foreach() loop.
This code is much easier to read and with less code repetition. But the downside is the if() grows up as the loop grows.
Which do you prefer?
Which is the better approach in your opinion?
I know for small amount of loops, second approach may be favorable.
But think about 100 loops that got executed each time a visitor refresh a page. It goes up quite fast with that.
-stndn.