This is a totally random idea. Sometimes, when I’m constructing a while()
loop in CFML, I’ll add some sort of a fail-safe during development so that I don’t accidentally kick-off an endless loop that crushes my CPU. Something like:
<cfscript>
i = 10;
failsafe = 1000;
while ( i ) {
i++; // ERROR: This should have been "--", loop will never end.
// DURING DEVELOPMENT, while I am figuring out my loop logic, I might include
// something like this as failsafe to make sure I don't crush the CPU.
if ( ! --failsafe ) abort;
}
</cfscript>
This way, while I’m still building-up my algorithm, I can rest easy knowing my loop will end no matter what (with an abort
, not a false-positive). So, my thought is, would anyone be interested in have a meta-attribute on the loop itself. Something like:
<cfscript>
i = 10;
while ( i ) maxIterations = 1000 {
i++; // ERROR: This should have been "--", loop will never end.
}
</cfscript>
This wouldn’t be for production use - only for development (though, onus is on the developer to remove pre-deployment). And, if the loop exceeded the maxIterations
count, Lucee would throw some sort ouf out-of-bounds error.
The Lucee language already has similar syntax with things like localmode
:
public void function doIt() localmode = "modern" {
// ....
}
… which is why this other idea occurred to me.
It feels strange to only have something that is development focused. But, on the other hand, I’ve only ever used loop times = 10 {}
in R&D, never in production. So, not the craziest idea.