3 ms·
My scenario is: * There's a function f(int, double), called in ~100 places, written by many different people. * For some reason I decide to change it to f(dou
by yongjik 10y ago
My scenario is:
* There's a function f(int, double), called in ~100 places, written by many different people.
* For some reason I decide to change it to f(double, int). Consistency, or preparing for some other refactoring, whatever.
* I have to track down ~100 occurrences of f and exchange arguments. Time-consuming but no big deal.
* If any code was dependent upon compiler silently evaluating the arguments in a particular way, then the code was broken, and reasonably competent coders don't write too much broken code. (Moreover, such a dependency is 99% likely to be broken by random changes in codes or compiler options, so chances are that I wouldn't encounter too many such bugs.)
In your world, it is just about impossible. If I want to go ahead, I could either change every occurrence into:
int arg1 = ...;
double arg2 = ...;
f(arg2, arg1);
...or pore through every line calling f to see if it's safe.
C++ already has a reputation of being a difficult language to refactor, and your proposal will make it about impossible.
- ScottBurson 10y agoI've spent over three decades using languages that guarantee left-to-right evaluation order (Common Lisp and Java), and I have not found this to be a problem in practice.
- byuu 10y agoAh, I understand what you're saying now. I guess we'll have to agree to disagree, then. I am much more interested in predictability in my code than I am about reordering arguments in mature codebases. Lots of languages guarantee expression ordering to follow precedence and associativity rules, and I've never heard anyone say that it was a problem to refactor their code as a result. Whereas I am 100% certain that there are lots of codebases where this is a ticking timebomb with developers unintentionally relying on the order their compiler decides to evaluate expressions in. And it will blow up when, not if, the GCC devs find some micro-optimization and decide to reverse things on them. And that's not just a problem for them, it's a problem for everyone who relies on their code.