Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!uhccux!munnari.oz.au!cs.mu.oz.au!ok From: ok@cs.mu.oz.au (Richard O'Keefe) Newsgroups: comp.lang.c Subject: Re: swap(x,y) Summary: Strachey quote from 1962 Message-ID: <1989@munnari.oz.au> Date: 1 Sep 89 01:46:15 GMT References: <8350@boring.cwi.nl> <1545@l.cc.purdue.edu> Sender: news@cs.mu.oz.au Lines: 31 In article <1545@l.cc.purdue.edu>, cik@l.cc.purdue.edu (Herman Rubin) writes: > In article <14479@haddock.ima.isc.com>, karl@haddock.ima.isc.com (Karl Heuer) writes: > > In article <230@crdos1.crd.ge.COM> davidsen@crdos1.UUCP (bill davidsen) writes: > > >However, there are reasons for doing tricks such as the XOR thing. They > > >enable me to write a macro which does the swap for any type. > > Only for integral types. It won't work on float, pointer, struct, etc. ... > This is another example of keeping the tools from the programmer. On the 18th of April, 1962, Christopher Strachey said: Writing programs needs genuis to save the last order or the last millisecond. It is great fun, but it is a young man's game. You start it with great enthusiasm when you first start programming, but after ten years you get a bit bored with it, and then you turn to automatic-programming languages and use them because they enable you to get to the heart of the problem that you want to do, instead of having to concentrate on the mechanics of getting the program going as fast as you possibly can, which is really nothing more than doing a sort of crossword puzzle. I shouldn't need to point out that "the XOR thing" has the extremely nasty "feature" that swap(x[i], x[j]) will set x[i] to 0 when i = j. I shouldn't need to point out that some programming languages (Burroughs Extended Algol, Pop2, Algol 68, Dijkstra's notation) can do exchanges without XOR hacks, but that these languages remain in a minority because exchanges are rare and easily avoidable at low cost.