Rick Schaut writes about stupidity of the XOR trick these days:
So, not only is the XOR swap stupid because it's obscure, it's stupid because, with modern optimizing compilers, the eventual result often ends up being contrary to the intended result of using the coding trick in the first place.
The moral is, before you consider using some obscure coding trick for the sake of performance, write up some sample code, and take a look at the actual code your compiler generates. More often than not, you'll find that the less obscure method results in better code.That great deal smells declarative programming style! Just declare what you want and let compiler do optimization tricks. +1. After years of XSLT coding and an optimizing XSLT compiler I developed once upon a time I'd say what Rick said perfectly fits XSLT/XPath/XQuery family. It's the most difficult thing when going XSLT lerning curve - to stop thinking procedurally and start thinking declratively. A common sample is alternating in XSLT - whenever you need to distinguish odd and even rows, do not go thinking about manual counting, incrementing of a variable etc. That's not the way to go. Just rely on XSLT processor and declare you are interested in even (position() mod 2 = 0) or odd (position() mod 2 = 1) rows.
Leave a comment