Forum OpenACS Development: Re: Do not use namespace qualification for PL/SQL variables

It is still here: https://openacs.org/doc/openacs-4-6-3/eng-standards-plsql.html - Point 6.

Maybe we should just use the PostgreSQL conventions in Oracle.

Guess that sounds like a TIP right?

Maybe there is a way to do such a conversion semi-automatically, have to think about it.

Andrew, I'm guessing you mean p_* for the passed in parameters, and v_* for the local variables. This convention makes it easy to figure out where a variable came from without having to trace through a bunch of code just to make sure. However, once you have done these two simple changes, sometimes you still need the package.proc.var name qualifiers in Oracle. I seem to remember that cursor packages are picky if you don't do everything exactly right.

Tom, I didn't remember exactly conventions OpenACS has used before, but yes what you describe for p_* and v_* variables sounds excellent to me.

(At aD, I think the rest of the Muniversal team and I had written reams of custom PL/SQL in a similar style before most of the aD "core team" started using PL/SQL much at all. [grumble grumble])

If you occasionally need to use Oracle's namespace qualification feature on local variables, fine, that's what it's there for. But it would would much nicer to see it only where it's actually needed, not willy nilly all over the place in order to make the variable names as hard to read as possible.

That old style guide Dirk links to above seems awfully mis-guided on this relatively trivial point. Note that the authors seemed to confuse two unrelated things, they say: "Name parameters as simply as possible" and "To achieve this we must fully qualify arguements passed into procedures" - nonsense, the second statement does not follow from the first.

Personally it never bothered me at all to call PL/SQL functions with parameters named "p_foo" rather than "foo", but if you really hate that, that does not mean that your only other option is to use namespace qualification all over the place. Rather obviously, you can simply declare a "p_foo" or "v_foo" variables near the top of your function, and initialize "v_foo" to the passed in value of "foo". Not necessarily ideal, but for a long function, that is going to be much clearer than prefixing the variable with the function name dozens of times throughout the code.

Andrew, I agree, using the function name to qualify a local variable is a useless idea, an idea that is pretty much solved by appending p_ to every passed in parameter, or in pg, aliasing the same way. And every locally declared variable gets appended with v_. The place to be verbose, if at all, in a variable name is in the meat of the name, not in some prefix. Of course what is clear to me might be confusing to someone else. So the debate may continue.