www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: assignment: left-to-right or right-to-left evaluation?

reply bearophile <bearophileHUGS lycos.com> writes:
Georg Wrede:

 arra[i] = arrb[i++];
 arra[i++] = arrb[i];
 I'm not sure that such dependences are good code.
 By stating a definite order between lvalue and rvalue, you
 would actually encourage this kind of code.

I agree that putting such things in code is bad, but nowadays the solution adopted by C is Just Wrong. To help avoid bugs from your programs the language has to avoid undefined behaviors (this is one of the lessons of Java). So the solutions are to define such behaviors as Andrei suggests, or to forbid such code. I can accept both ways. I am used to Python and I think I can appreciate the Python solution better, but the Java solution too is better than having undefined behavior in a modern language. So thank you Andrei for this work. Bye, bearophile
May 15 2009
next sibling parent reply Georg Wrede <georg.wrede iki.fi> writes:
bearophile wrote:
 Georg Wrede:
 
 arra[i] = arrb[i++];
 arra[i++] = arrb[i];
 I'm not sure that such dependences are good code.
 By stating a definite order between lvalue and rvalue, you
 would actually encourage this kind of code.

I agree that putting such things in code is bad, but nowadays the solution adopted by C is Just Wrong. To help avoid bugs from your programs the language has to avoid undefined behaviors (this is one of the lessons of Java).

If Walter had ulimited time, the of course I'd favor either defining the precedence, or then enforcing errors on them, and not leaving them undefined. Or, probably, with Walter's unlimited time, I'd vote for a system that is the Theoretically Best mix of programming praxis and compiler enforcement.
 So the solutions are to define such behaviors as Andrei suggests, or
 to forbid such code. I can accept both ways.

 I am used to Python and I think I can appreciate the Python solution
 better, but the Java solution too is better than having undefined
 behavior in a modern language.

May 15 2009
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Georg Wrede:
 If Walter had ulimited time, the of course I'd favor either defining the 
 precedence, or then enforcing errors on them, and not leaving them 
 undefined. Or, probably, with Walter's unlimited time, I'd vote for a 
 system that is the Theoretically Best mix of programming praxis and 
 compiler enforcement.

Java is currently the most used language because it gives a big help in avoiding bugs or fixing them. And today Java is not a slow language. Java shows why having undefined things is bad for productivity and doesn't give much performance or portability. Bye, bearophile
May 15 2009
prev sibling parent reply Christopher Wright <dhasenan gmail.com> writes:
Georg Wrede wrote:
 bearophile wrote:
 Georg Wrede:

 arra[i] = arrb[i++];
 arra[i++] = arrb[i];
 I'm not sure that such dependences are good code.
 By stating a definite order between lvalue and rvalue, you
 would actually encourage this kind of code.

I agree that putting such things in code is bad, but nowadays the solution adopted by C is Just Wrong. To help avoid bugs from your programs the language has to avoid undefined behaviors (this is one of the lessons of Java).

If Walter had ulimited time, the of course I'd favor either defining the precedence, or then enforcing errors on them, and not leaving them undefined.

$ su walter $ ulimit -t unlimited
May 16 2009
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
Christopher Wright wrote:
 Georg Wrede wrote:
 bearophile wrote:
 Georg Wrede:

 arra[i] = arrb[i++];
 arra[i++] = arrb[i];
 I'm not sure that such dependences are good code.
 By stating a definite order between lvalue and rvalue, you
 would actually encourage this kind of code.

I agree that putting such things in code is bad, but nowadays the solution adopted by C is Just Wrong. To help avoid bugs from your programs the language has to avoid undefined behaviors (this is one of the lessons of Java).

If Walter had ulimited time, the of course I'd favor either defining the precedence, or then enforcing errors on them, and not leaving them undefined.

$ su walter $ ulimit -t unlimited

I swear I wanted to post this too! :o) Andrei
May 16 2009
parent Georg Wrede <georg.wrede iki.fi> writes:
Andrei Alexandrescu wrote:
 Christopher Wright wrote:
 Georg Wrede wrote:
 bearophile wrote:
 Georg Wrede:

 arra[i] = arrb[i++];
 arra[i++] = arrb[i];
 I'm not sure that such dependences are good code.
 By stating a definite order between lvalue and rvalue, you
 would actually encourage this kind of code.

I agree that putting such things in code is bad, but nowadays the solution adopted by C is Just Wrong. To help avoid bugs from your programs the language has to avoid undefined behaviors (this is one of the lessons of Java).

If Walter had ulimited time, the of course I'd favor either defining the precedence, or then enforcing errors on them, and not leaving them undefined.

$ su walter $ ulimit -t unlimited

I swear I wanted to post this too! :o)

Nice quips, from you both... :-) But there's a bug in the algorithm. A more correct version would be: $ su $ ulimit -t unlimited $ su walter $
May 16 2009
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
bearophile wrote:
 Georg Wrede:
 
 arra[i] = arrb[i++];
 arra[i++] = arrb[i];
 I'm not sure that such dependences are good code.
 By stating a definite order between lvalue and rvalue, you
 would actually encourage this kind of code.

I agree that putting such things in code is bad, but nowadays the solution adopted by C is Just Wrong. To help avoid bugs from your programs the language has to avoid undefined behaviors (this is one of the lessons of Java). So the solutions are to define such behaviors as Andrei suggests, or to forbid such code. I can accept both ways. I am used to Python and I think I can appreciate the Python solution better, but the Java solution too is better than having undefined behavior in a modern language. So thank you Andrei for this work.

Well put! Java has definitely taught us that a clean, robust language definition can go a long way. (And also that marketing helps :o)). I think Java is a bit like the STL in a certain respect: there's a feeling of "before" and "after". Java has shown not only that defined behavior is good, but also that it can be incorporated into a practical language. Andrei
May 15 2009