I know this is a little opinion based, but so is Mathematica style guide and similar topics.
The issue is important so I think this topic will be beneficial for future visitors.
Q: So lowerCaseFunctionName
or UpperCaseFunctionName
convention for symbols exported from package for users. And why?
I was using lowerCaseCamelCase
convention but Szabolcs made some valid points and now I'm not totally convinced. (still using it though)
Let me leave a link to those comments.
I'm still using
lowerCaseCamelCase
because I don't have to worry in future and push fixes which only rename conflicted symbols.In my case packages are quite localized but if you build e.g a package with wide applications, it may be that WRI will release something similar.
Then I'd rather
Protect
all exported symbols so a user won't be able to do anything wrong, than go back to that again.
https://reference.wolfram.com/language/tutorial/DefiningVariables.html
Answer
Like Leonid, I also prefer capitalized public package symbols. He gave the argument that this is the conventional way to do it and discussed conflicts with builtins (unavoidable) vs conflicts with other packages (avoided through the use of contexts). I would like to add some additional arguments in favour of capitalized package symbols:
The reason why it is recommended to use lower-case symbols for everyday work (i.e working in Global`
) is to avoid accidental conflicts with built-in symbols or package symbols. This of course only works if package symbols are all capitalized, just like builtins. Does the same argument about keeping symbols lowercase apply for packages as well, i.e. should packages try to avoid conflicts with the System`
context the same way?
There's a big difference between how I write Mathematica code during everyday for or for a package that I might share with others.
Most of the code I write during normal work is written quickly, focuses on getting the task done, and eventually gets thrown away (or replaced). I want to be able to work fast and not worry about name collisions so I use only lowercase symbols.
Package code on the other hand is well thought through and is usually maintained over a long span of time. In this situation having to pay attention to avoiding conflicts with builtin symbols is not a big inconvenience. If a new version of Mathematica comes out and the package conflicts with it, I would just fix that in the next release of the package. But as Leonid said, one might as well put in some thought to at least try to avoid names which might show up in future versions. To sum up: In packages there's much less need for such a safeguard against accidental conflicts with builtins because accidents can be avoided through care. There's also no need to avoid conflicts with other packages because contexts take care of that.
Another difference between everyday code and packages is that packages are used by many people. The package users will typically not be familiar with every single function from the package, and in practice they do treat the package similarly to builtins. It will be beneficial if package symbols do look like builtins so users can just follow the usual lower-case convention and be confident that they won't accidentally conflict with some package symbol they didn't even know about.
Most of what I said here applies to polished packages which might be shared with a large audience. I do not follow the same capitalization guideline for every single .m
file I write and use privately, only for packages which were planned as packages from the beginning and which are relatively well thought through.
Comments
Post a Comment