In article <h2l36k$q5...@reader1.panix.com>, kj <no.em...@please.post> wrote: > > >I'm will be teaching a programming class to novices, and I've run >into a clear conflict between two of the principles I'd like to >teach: code clarity vs. code reuse. I'd love your opinion about >it. > <SNIP> > >This seemed straightforward enough, until I realized that, to be >useful to my students in their homework, this _binary_search function >had to handle the case in which the passed function was monotonically >decreasing in the specified interval... > <SNIP> > >Here's the rub: the code above is more general (hence more reusable) >by virtue of this trick with the sense parameter, but it is also >a bit harder to understand. > >This not an unusual situation. I find that the processing of >abstracting out common logic often results in code that is harder >to read, at least for the uninitiated...
Yes, of course. You're teaching, say, green belt programmers. Good reusable code requires a fifth dan. You may not be up to it yourself (no offense intended), let alone your students. Writing a reusable binary search is a very different assignment from being able to code/use it in a concrete example. Their choice must be between *writing* a one-off binary search, versus *using* a brilliantly code, brilliantly documented binary search that has been given beforehand. Even assuming the reusable code is perfect in all sense, reusing may be more effort than writing from scratch. Then *you* have to explain them about the benefits of reuse. (The other benefits, of course.) > >I'd love to know your opinions on this. You're welcome. >kj Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. alb...@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list