Lima Bean
10-16-2011, 01:54 PM
Recursive coding is pretty, but it can hide small things that can and will lead to
"features" and uninteneded consequences as a code base grows.
In a time gone by loops could have been taken for granted, because the hardware was sequential and much slower, but with the advancement of speed and capacity this has changed.
With each new processor there are also new machine instructions, that means even the simplest of primitives, like int and str, are shuttled around the cache registers and from processor to processor differently as well. The probability of "hiccups" will also increase with the more cores on the die. In addition to this, more coding is coming alongthat handles all Oses and file systems.
A caveat must be mentioned here, loops are executed from the point of the computer, not the coder. This is very easy to forget as confidence and skill increase. Why mention the obvious?
repeat
....
until Boolean
while Boolean do
.....
Speed is what the repeat loop is good for, but how many lines are parsed and executed before the value of until is returned or met? If it is parsed from the top down, then this will cause an unintended error. On the flip-side what if it is parsed from the bottom up? In that case the while loop will be passing a bad Boolean.
Yes, stuff does happen, and loops can be solid, but how many lines are executed and which way are they parsed? Once that is established then "features" can be planned, not unexpected pluses.
Both of these links provide code and comparison of more advanced looping techniques
http://blogs.oracle.com/greimer/entry/best_way_to_code_a
http://www.codeproject.com/KB/cs/FastLessCSharpIteration.aspx
"features" and uninteneded consequences as a code base grows.
In a time gone by loops could have been taken for granted, because the hardware was sequential and much slower, but with the advancement of speed and capacity this has changed.
With each new processor there are also new machine instructions, that means even the simplest of primitives, like int and str, are shuttled around the cache registers and from processor to processor differently as well. The probability of "hiccups" will also increase with the more cores on the die. In addition to this, more coding is coming alongthat handles all Oses and file systems.
A caveat must be mentioned here, loops are executed from the point of the computer, not the coder. This is very easy to forget as confidence and skill increase. Why mention the obvious?
repeat
....
until Boolean
while Boolean do
.....
Speed is what the repeat loop is good for, but how many lines are parsed and executed before the value of until is returned or met? If it is parsed from the top down, then this will cause an unintended error. On the flip-side what if it is parsed from the bottom up? In that case the while loop will be passing a bad Boolean.
Yes, stuff does happen, and loops can be solid, but how many lines are executed and which way are they parsed? Once that is established then "features" can be planned, not unexpected pluses.
Both of these links provide code and comparison of more advanced looping techniques
http://blogs.oracle.com/greimer/entry/best_way_to_code_a
http://www.codeproject.com/KB/cs/FastLessCSharpIteration.aspx