MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Function and object naming conventions

  • To: mathgroup at
  • Subject: [mg106814] Re: Function and object naming conventions
  • From: Albert Retey <awnl at>
  • Date: Sun, 24 Jan 2010 05:40:18 -0500 (EST)
  • References: <21622849.1264068058488.JavaMail.root@n11> <> <hjeq5f$fmp$>


> Thanks to all for the many great replies in this thread.  Name
> conflicts really seem to be a common problem with several of the
> Mathematica archive packages that I've tried.   Sometype of naming
> convention practice seems important. E.g. - the last one I tried was
> a package on importing triple variables for plotting:
> ----------- Import["ListToArray.m"]

You should recognize that the standard way to "import" a Mathematica
Package file is via Needs or Get. You might want to look these and their
differences/applications in the documentation...

> ListToArray::shdw: ListToArrayappears in multiple contexts
> {ListToArray`,Global`} definitions in context 'ListToArray' may
> shadow or be shadowed by other definitions. -----------
> For VBA and javascript, I usually just append my initials for
> publically exposed packages to prevent conflicts.

I don't know VBA and javascript very well, but from most other languages
I know there are possibilities to load ("import", Needs ...) packages
without necessarily expose their namespaces and thus avoid any
conflicts. Actually, as usual, this can be accomplished with a few lines
of somewhat hackish mathematica code, e.g.:

Rod = 9;

Quiet[Needs["Units`"], General::shdw];
$ContextPath = DeleteCases[$ContextPath, "tmp`"];

So after this, you have the global Rod (Global`Rod) which is still set
to 9 and you have the Units`-Package Rod (Units`Rod) available with it's
"full qualified name", Units`Rod. This way you can have loaded and use
as many packages with conflicting names as you want, of course at the
cost of having to use the lengthy full qualified names.

There are two open questions: Why do I need the Quiet within the
BeginPackage/EndPackage? Actually $ContextPath does not contain Global`
when the Needs is executed, so I would consider it to be a bug that the
shadow message is issued. Are there good reasons for the Message to be
issued nevertheless?

The other question is why there are no functions to do the above (and
maybe more) in a more obvious way, I think a better handling of
namespaces would help on the way to qualify Mathematica to be used for
more complex programming tasks...



  • Prev by Date: Re: NotebookGet/Read/EvaluateSelection Issues
  • Next by Date: Re: Using "If" and "NDSolve" together
  • Previous by thread: Re: Re: Function and object naming conventions
  • Next by thread: Re: Function and object naming conventions