If only there were a language construct to handle this case...
-
Just stumbled across this:
int page = 1;
while (true) {
if (page > pageCount) {
break;
}/\* Do stuff with page \*/ page++;
}
Considering how common it is to use an index in a loop, you'd think the language designers would have a better way of dealing with this... :laugh: EDIT: even better, in 2 of the 3 places using page, it uses
page - 1
:facepalm: -
Just stumbled across this:
int page = 1;
while (true) {
if (page > pageCount) {
break;
}/\* Do stuff with page \*/ page++;
}
Considering how common it is to use an index in a loop, you'd think the language designers would have a better way of dealing with this... :laugh: EDIT: even better, in 2 of the 3 places using page, it uses
page - 1
:facepalm:If I use ILASM to disassemble .NET coe, it frequently decodes for-loops like this. Maybe the original developer appropriated (ie. stole) some code using similar techniques without checking the output carefully. (Personally, I use it to check correct usage of poorly documented APIs, but I'm sure many are less scrupulous).
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
If I use ILASM to disassemble .NET coe, it frequently decodes for-loops like this. Maybe the original developer appropriated (ie. stole) some code using similar techniques without checking the output carefully. (Personally, I use it to check correct usage of poorly documented APIs, but I'm sure many are less scrupulous).
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
Rob Grainger wrote:
it frequently decodes for-loops like this
Of course, the simplest way to write a loop in an assembly-like language is something like:
// for ([assignment]; [condition]; [increment]) { [body] }
[assignment]
start_loop:
if ![condition] goto end_loop
[body]
[increment]
goto start_loop
end_loop:That doesn't mean it should be written that way in a high-level language though, even if you technically can.
-
Rob Grainger wrote:
it frequently decodes for-loops like this
Of course, the simplest way to write a loop in an assembly-like language is something like:
// for ([assignment]; [condition]; [increment]) { [body] }
[assignment]
start_loop:
if ![condition] goto end_loop
[body]
[increment]
goto start_loop
end_loop:That doesn't mean it should be written that way in a high-level language though, even if you technically can.
Rob's suggesting the duhveloper just stole recompiled code out of reflector without thinking; and building in logic to detect all 90 bazillion high level constructs and correctly promote the result of reflection to them instead of the simplest valid code is 99.9999% of the work involved in writing a reflection tool. The length of the long tail means that it's a job that will probably never be done.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
-
Rob's suggesting the duhveloper just stole recompiled code out of reflector without thinking; and building in logic to detect all 90 bazillion high level constructs and correctly promote the result of reflection to them instead of the simplest valid code is 99.9999% of the work involved in writing a reflection tool. The length of the long tail means that it's a job that will probably never be done.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
Thank you for saving me the effort, exactly my point.
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.