Forum OpenACS Development: Re: connection-global cache: namespace problem?

Collapse
Posted by Roberto Mello on
This has nothing to do with your problem, but it will help you in debugging and will improve readability of your code.

I noticed that much of the namespaced code coming in to OpenACS is following the style you use:

namespace eval foo {
    ad_proc -public bar {
    }
}

This looks innocent, but there are several problems with doing things this way.

It makes it harder to read, because you have to keep all your procs in one big block. When reading through some code in some packages that have many procs declared that way, I end up having to scroll back all the time to know in which proc or namespace I am in.

Also it's hard to make sure you're in the right level of indentation, and it unnecessarily pushes one more level of indentation in.

There is what I think is a better way. acs-templating uses the following style, and I think it's a much better style to use accross OpenACS.

namespace eval foo {}

ad_proc -public ::foo::bar {
}

This way you can clearly see that "bar" belongs to the "foo" namespace. Your proc won't seem endless, because you're at the first level of indentation.

Overall I think it's much more readable and maintanable.

-Roberto

Collapse
Posted by Bart Teeuwisse on
Another important benefit from Roberto's method is that it allows Emacs to index the proc ::foo::bar with the fully qualified name rather than bar.

When bar is called outside the namespace foo the procedure is called with the fully qualified name ::foo::bar. Looking up the proc's definition with Emacs's tag search (M-.) only works with Roberto's method.

/Bart