Forum OpenACS Development: Re: db_multirow and db_foreach -unclobber
1) Nothing's been changed yet.
2) The only overhead it adds if you don't use it is two if's with very simple conditions.
3) It only unclobbers when there's a code block, because it's only when there's a code block that db_multirow clobbers any variables (a current slight difference from Tcl's foreach, actually).
4) I think I disagree with this statement, although I'm not sure what "one thing" means in this context: "Pesonally I feel it is the job of the page programmer to work out these naming conflicts. The tcl/adp page are one thing. In fact the entire set of code that is executed in response to a request is one thing. Ignoring this fact will lead to bugs which are hard to trace."
The whole idea behind ad_page_contract is to document which parameters the page takes and which properties it supplies for the template designer. That's why ad_page_contract is defined in a file called tcl-documentation-procs.tcl, and that's why I still consider page parameters and properties, including the names of columns in a multirow proprety, part of the page's public API.
It seems like we disagree on this point. Fair enough.
5) It's not a non-core change, because since I'd run into this problem before while following the coding style which I prefer and thought was fairly standard, I figured it was a general problem and I believe these are best solved with general solutions.
6) Yes, the logger page I am working on is going to become part of the newly released logger pacakge, but obviously if people (and yes, I'd like to hear the opinions of more people) are opposed to adding -unclobber, I'll have to rewrite things a bit.
7) Please don't take your general frustration out on me. I haven't committed anything. I posted to ask for people's opinion. I didn't manage to get opinions from many different people, but I did get your opinion quite clearly, thank you. :)
An interesting point is that db_multirow, without a foreach block, doesn't clobber the local vars. This means the original intent of db_multirow was to not create these vars in the local context. I believe that the foreach code block was added recently to make it possible to do per row processing. Given that the new db_multirow combines features of the old nonclobbering db_multirow and the clobbering db_foreach, I can see the reason behind your original proposal as it applies to db_multirow.
For db_multirow, the question of what should be the default (-clobber/--unclobber) is still important. If you look at ad_page_contract properties, the multirow is usually only specified as the array name, not the individual column names. If you add a foreach block to the db_multirow for the purpose of, for example, adding a calculated column to each row, your intent is not to have to deal with all these variables that now exist, and possibly have overwritten, your local variables. I'm almost to the point of thinking that -unclobber should be the default, so that things match up with the original db_multirow behavior.
A similar intent could be applied to db_foreach. Many times I have used db_foreach for a purpose not related to setting local variables, and never for setting the variables that are reset for each iteration of the loop.
Lars, I'm sorry that I misintrepreted your reasons for the changes.