Forum OpenACS Development: Re: db_multirow and db_foreach -unclobber

Posted by Peter Marklund on
Tcl's upvar feature is very powerful but should be used with great caution. In general, it is not a good idea for a procedure to clobber variables in its callers namespace unless it is exceedingly clear to the calller that this happens and the caller can control it. I don't think any looping construct should clobber variables in the surrounding code. As an example of this idea, consider the for loop in Java where the count variables only lives inside the scope of the loop. This is not "musguided purism", simply sound software practice. Procedures should be cohesive and have a very simple and well defined contract. Clobbering doesn's serve any of these two goals.

Lars and I both got burnt independently of eachother by the current behaviour of db_multirow. Changing the default would  mean that we would have to add the -clobber switch in probably less than 1% of invocations of the proc. That seems like a very cheap price to pay for making db_multirow more robust by making it interact less with its calling environment in the 99% of cases where this interaction is not needed or desired.