Forum OpenACS Q&A: namespaces: to use or not to use?

Collapse
Posted by Roberto Mello on
I've been developing some OpenACS 4 packages (Paypal, Cookbook, Wiki)
and have been wondering if I should put my procs under namespaces or not.

Some packages use them, while others don't. It seems like a good
practice to use them. Thoughts?

Collapse
Posted by Yonatan Feldman on
one thought: use them.
Collapse
Posted by Don Baccus on
another thought: use them
Collapse
Posted by Jun Yamog on
I don't know if it should count as a thought.  But I use them.  Will there be standardization on this?

Use namespace... or never user namespace.

Also according to Rob Locke he read some issues regarding namespace that was brought up by Rob Mayoff.  <- did I spell his name correct, sorry if not.  Rob L. wrote a small hello world adp to show me how namespace behave in aolserver.  I am sorry I forgot about the issue.  Maybe if someone else can remeber this please post it.

Is someone already starting a doc on simple standards for OACS?  I know Don will say... would you like to volunteer for that.  Sure thing just give me access to file storage.

I can't contribute much but I think here are for starters for that small text file "Simple OACS dos and donts"

1. Use namespace

2. User "return_url" as a var name for blah blah.

3. Avoid putting in tcl logic on adp pages if possible.  Use foo.tcl and foo.adp.  The same way is true for tcl... avoid putting in html on tcl.

4. Use foo_p for boolean vars

5. Use package_key__foo/package_key.foo for db api.  Use package_key::foo for tcl api.

6. Use ad_form

The above is not meant to be a do list but more of atleast in the future the code will be uniform and standard.  Old code can be change as time goes by.  Also the above are just examples from me so not all maybe correct.

Collapse
Posted by Don Baccus on
Would you like to volunteer to do this? :)

There used to be some coding standards from aD for OpenACS 4 lying around their website, I do believe.  They may've even made it into the ACS 4.x distros, does anyone know?

I'd start doing a little searching as a first step if you're interested in spending a little time on this ("foo_p" for predicates, for instance,  was a documented aD coding standard).

I've mumbled to a couple of folks about wanting something like this so would be willing to review anything you come up with and help out by editing, etc.

Collapse
Posted by Torben Brosten on
As developer related info, it seems to me that this information belongs in Part III of the OpenACS 4.5 documentation ( https://openacs.org/doc/openacs-4 ), such as Programming with AOLserver ( https://openacs.org/doc/openacs-4/programming-with-aolserver.html ) etc.. sorry I'm not able to be more specific at this time.

You could search for the page you feel is most appropriate, then "Add a comment" at the bottom of the page for the documentation editors to include in the body of the document on the next update.

Collapse
Posted by Jun Yamog on
Hi Torben,

Thanks for the reminding about the doc add a comment feature.  I was only able to add suggestion #3.  The other suggestion seems to be out of place.

Hi Don,

Yes I am willing to volunteer on this.  Just give me new-file-storage access.  I wish to make a small doc titled "Simple OpenACS dos and donts".  That will contain the top 20 or 50 things to do or dont.  Why so little?  The doc is meant for lazy developers like me.  It may or may not work but its worth a try.  I have listed 6 unvalidated suggestions.  I will basically use the bboard to gather the top 20 or 50 things.  And put it in to this simple doc.  Maybe we can add sections to the main documentation from this simple doc.

Hmmm maybe entitle it to be "Simple OpenACS guide for Lazy Programmers".... hehehehe.

Collapse
Posted by Stephen . on
one question: why?
Collapse
Posted by Jun Yamog on
Hi Stephen,

Not sure if it will help, but it might.  Its worth a try.  We can just start with 20 things.  Each item may point to some real documentation for further reading.

I think it will help.  Like for example the original question posted by Roberto.  I am sure Roberto read the docs while he edited and added to them. But it seem those docs did not have all the answers or it may have but was deep down in it.

If you think the idea is just a waste of time then I will throw away the idea.  Do you think its worth putting some small doc about the top 20 things we must know?  I am volunteering to maintain the doc and will add the first 5.  Maybe some will add until it reaches 20.

What do you think is worth some volunteer effort?

Collapse
Posted by David Kuczek on
I think that a doc on simple oacs standards would be especially useful for developers just starting off with 4.5... The problem is that sometimes you don't exactly know (like Roberto) what to or not to use just because it has or hasn't been used in different packages... A standard would really help on that!
Collapse
Posted by Stephen . on
I was referring to the original question, "should I use namespaces", and the just-cos answers.  I was wondering what the advantage was, as one of the only differences I've noticed is that depending on how the namespaced proc is specified, the api documentation is broken. Oh, and maybe you can't grep for usage of the proc anymore.  Why is ad::conn better than ad_conn?

Sure, a guide sounds great.  Looking forward to it.

Collapse
Posted by Jun Yamog on
Hahaha... sorry about that Stephen.  The design thread has probably gotten into me.

I can't answer your question..  But it seem people say yes to it and I also blindly use it.  And it will make the top 20 list if more authorative people say so.

Collapse
Posted by Yonatan Feldman on
stephen:

1) proc name collision avoidance

2) package consistency; i.e. pl/sql package named foo and tcl package named foo

3) ability to call procs by their real name from within a namespace; i.e. within namespace foo i can call function foo::bar by just saying bar, elsewhere i call it with foo::bar

ad_conn is meaningless, ad::conn is also meaningless. i am against putting names of people or companies in proc names. it only adds clutter and needless typing. if it's a matter of ego and recognition stick an @author doc tag in the ad_proc doc argument, which you should do anyway so that people know who to contact about a proc.

namespaces and proc names should be meaningful and should help categorize functionality. take as an example, the new permission:: namespace. newbies (and others) can very easily tell what this namespace is about and how to use it, check out http://yourserver/api-doc/procs-file-view?path=packages/acs-tcl/tcl/acs-permissions-procs.tcl, it's not the best documented package, but it's still fairly clear.

this brings me to another practice i think we should adopt everywhere. one of the reasons i created the new permission:: namespace is the use of named parameters. i think we should all use them everywhere. i have spent countless hours chasing down bugs all over openacs 4.x that boiled down to people passing arguments in the wrong order to functions. one of the common ones is ad_permission_p and it's siblings. this could have been much easier to find and fix (if not avoid all together) if the function had used named parameters. yes they are a longer to type, but i believe that is typing well spent. it helps with code self documentation and maintenance, it helps avoid situations like the one i explained above. i think we should make it a requirement for api's to use named parameters, and that we should slowly move the core to all named parameters, it's not that hard (of course changing acs service contract to use named parameters would be incredibly useful too).

i think those are enough reasons

Collapse
Posted by Stephen . on
Proc names already do not collide, but they're prefixed with something-underscore rather than something-double-collon.

What the something prefix should be is a naming, not a namespace issue and applies equally whether the separator is an underscore or two colons. Your suggestions for names sound good to me, as is your suggestion that named parameters be used.

The typing saved by calling procs with a shorter name from within packages is minimal, and so far not an often used feature.  It also goes against the grain of being explicit to aid readability at the expense of extra typing introduced by widespread use of named parameters.

What is actually being described here is a complete renaming of the toolkit API, not a technical fix for which the Tcl namespace feature is appropriate. I'm not necessarily against this, but if we clearly label it for what it is we can adress any problems.

Developer Tips are one band-aid solution to the problem of the toolkit being rendered largely a bad example of it's own usage because of API renaming.  'Band-aid' because documentation is a last resort ('no one reads documentation...'), by-example copying is a primary source of information.

If we're looking for developer guidlines then I would suggest the following:  If you rename APIs then also ensure all the code that references the old name is fixed.  At the least, fix the packages that are enabled with a default install.  At the very least, give a heads-up on the bboard.

Collapse
Posted by Jun Yamog on
Hi Stephen,

I don't plan to make my list a do list as I have stated above.  Its just a list that is approved by a good number of knowledgable person for FUTURE development.  (I also take no objection as an approval... the approval doesn't seem to come as I expected them to be).

Anyway atleast with the list future developments will have a better and consistent path.  If (big IF) use of namespace is agreed then future developments will just use it, that rather than what is happening now... some use it some dont.  A concrete example is Roberto's future packages.  If we had this small handy guidline he would not have to ask this question and design and code away.  If we had this guideline I would not have used mypackage_gettitle tcl api.  I would have used mypackage::gettitle since that is in the guidline.

I think what I should do is to state the goal of the doc right on top of the doc.  As not to confuse new developer in looking for ad::conn which does not exist.