4 ms·
Um, have you ever written code like this in a real program? Honestly? Why would you ever want to swap variables? (I mean, I remember doing this thing in TI-83+
by bkudria 17y ago
Um, have you ever written code like this in a real program? Honestly? Why would you ever want to swap variables?
(I mean, I remember doing this thing in TI-83+ BASIC, where valid variable names were limited to the letters of the alphabet ...)
- mojuba 17y agoCheck out some popular sorting algorithms, those that do the job "in place", i.e. without additional memory allocation.
- bkudria 17y agoYes... but how many times have you re-written a sort? (Where 'you' is your average programmer, or, even, the above-average programmer who reads technical blogs and toward whom this post is targeted)
- mojuba 17y agoIf you are an inventor of sorting algorithms, I'd guess you do that quite often. But seriously, does it really matter? Short functions or blocks with variables of local significance do exist. Swap() was just the first thing that popped up, probably because I like messing around with algorithms and re-implementing them. Which every self-respecting programmer, umm, should do, I think.
- wlievens 17y agoMost projects contain at least a handful of utility functions that your base library doesn't offer. These utility functions are largely independent of the problem domain, and often of a mathematical nature. Therefore, short, undescriptive variable names (such as 'x') are perfectly acceptable.