9 ms·
This is a cool theory, but why would it call the function again? Shouldn't it just give up? It's not like it would get a different result next time.
by astazangasta 10y ago
This is a cool theory, but why would it call the function again? Shouldn't it just give up? It's not like it would get a different result next time.
- mjevans 10y agoLet's assume that it has a set number of attempts each with some delay. Let's also assume that whatever this is has multiple instances for some reason; maybe it's something called as part of an update process for system accounting information. If every process on the machine did this every time it got re-scheduled? Yeah, I can see that.
- kazinator 10y agoCalling the function again when the user doesn't exist could in fact be nonsensical and wrong. It could be due to failing to break out of some loop or whatever, not necessary an explicit "we don't have the user; let's branch backwards" logic. Perhaps that looping was not discovered simply because that case doesn't arise: the user always exists. Except, oops, when it appears not to exist due to being pruned because of the "user" substring; then the incorrect backwards branch problem is exposed.
- TeMPOraL 10y agoCalling the function again may be entirely logical and may be because of independent state, e.g. locks or security. Think of the famous problem we had for decades with file deletion hanging for 10 seconds or so if you tried to delete a file in use. Somebody traced and disassembled the code; it was literally a hardcoded loop that did 10 iterations of attempting to get a lock on the file followed by sleeping one second if failed... The loop-and-sleep combo there might have been a hack, but it was excusable.
- thriqon 10y agoYou could image code like this: for (pos = 0; !found; pos++) { row = get_next_row(); if (strstr(row, "user") { // this is obviously a header row continue } if (strstr(row, user_name)) { found = 1; } }
- wingerlang 10y agofor (pos = 0; !found; pos++) This is so cool, I have never thought about this in like a decade of programming. I mean using a bool variable within a for loop.
- lmm 10y agoDon't do it in production code - indeed try to avoid languages where "for" allows such arbitrary constructs.
- TeMPOraL 10y ago> Don't do it in production code I'd say fair, but... > indeed try to avoid languages where "for" allows such arbitrary constructs. ... come on. I'd say - go for such languages, they give you if a tiny bit more expressive power than ones who don't let you write such a loop.
- lmm 10y agoAllowing the same statement to do any kind of arbitrary nonsense is not the good kind of expressiveness. Far better to separate your concerns, and keep the orthogonal parts orthogonal. C-style for mixes too many different things.
- TeMPOraL 10y agoSemantics of the C-style for loop are pretty well defined - it's: for(initialize form ; condition form ; step form) { loop body forms }. Ascribing any different meaning to it, like e.g. that all three forms in the loop header must be present or must refer to the same set of variables, is a mistake. That said, if one has an alternative that can express their intention better (like e.g. mapcar, foreach loop, Lisp's dotimes, etc.), one should use it instead.
- seanmcdirmid 10y ago
- Someone 10y agoThe programmers evidently didn't consider this failure mode. I guess they did consider others. Code could look like this: while(!done) { try { foo(); baz(); done = true; } catch(...) {} } with baz failing, but the retry present to handle cases where foo fails.