Another software engineering glitch in Cormen et al.
The authors of introduction to algorithms have a function that takes four arguments: an array, and three indices into that array, a low index (low), a middle index (mid), and a high index (high).
Of course, there is no computational reason to pass those three indices in any particular order: the computer doesn't care. So our only concern in deciding what to to order to pass them should be to make it easy for the programmer to remember the order and get it correct.
And what order makes that easiest? In a culture that reads left to right, I am pretty sure we should pass (low, mid, high). Right?
I spent a half hour looking for a bug, finally discovering it occurred because the authors decided the best order to pass these arguments in was (low, high, mid).
Seriously guys, WTH?
Of course, there is no computational reason to pass those three indices in any particular order: the computer doesn't care. So our only concern in deciding what to to order to pass them should be to make it easy for the programmer to remember the order and get it correct.
And what order makes that easiest? In a culture that reads left to right, I am pretty sure we should pass (low, mid, high). Right?
I spent a half hour looking for a bug, finally discovering it occurred because the authors decided the best order to pass these arguments in was (low, high, mid).
Seriously guys, WTH?
Shoulda used a language with named arguments.
ReplyDeleteWell, they are writing pseudo-code in no language at all, and they are trying to use only common features of most languages. So I understand them not using those.
Delete