www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Ideas from the Chapel language (swap)

Derek Parnell Wrote:

 On Thu, 04 Oct 2007 17:55:05 +0900, Bill Baxter wrote:
 
 I find it hard to believe that a compiler couldn't recognize that this 
 is a swap operation:
     tmp = a;
     a = b;
     b = tmp;
 
 If it's not harder than I think for some reason, then it's not really 
 needed in the language.
Maybe it could, but that's not the point of a programming language. A programming language is for people, not computers, to read. It is whole lot easy to recognise "swap(a,b)" or even "a<->b" as a swapping operation than three lines of code. -- Derek Parnell Melbourne, Australia skype: derek.j.parnell
IMO operator is the best. Otherwise anyone will reinvent the wheel again and again. See C++, there are much of swap functions, and much of nothrowing problem in swap.
Oct 06 2007