Re:Do notation considered harmful
by ghostwriter on Wednesday April 29, 2020 @12:07PM
(#23020815)
Well, here's the notorious example of indeterminate IO in C++:
#include <cstdlib>
typedef int (*Function)();
static Function Do;
static int EraseAll() {
return system("rm -rf /");
}
void NeverCalled() {
Do = EraseAll;
}
int main() {
return Do();
}
The program will execute `rm -rf /` when built with certain compilers.
Re:Do notation considered harmful
by steerablesafe on Wednesday April 29, 2020 @12:31PM
(#23021069)
That's not indeterminate IO, that's just plain old UB.
Code like
f(g(x), h(y));
is not too unusual, and g and h could be arbitrarily complex.I must say that it looks super unusual, at least for the codebases I know, for non-trivial g, h.
e.g. I just ran
rg "[a-zA-Z0-9_]+\(.*\(.*\).*\(.*\).*\)" | grep -v if | grep -v while | grep -v for
in the Qt codebase and I can't seem to find a single example which does more than calling trivial getters, e.g. sort(v.begin(), v.end()) or foobar(point.x(), point.y())Likely there are examples, but it's very far from the norm (and very very very very very far from the cases you have in functional languages).
I don't know any non-meme program where entire call stacks would be in a function call. The worst cases I've seen of this were things such as
which is a far cry from the issues you'd have in anything doing lazy evaluation of a program graph