[seqfan] Re: metadata for Mathematica code

Alonso Del Arte alonso.delarte at gmail.com
Thu Nov 12 05:35:33 CET 2015


I've thought a lot about this over the past week. I think a lot of these
problems come about because of meaningless function and variable names. a,
b, c, f, t, probably all the letters of the alphabet have been used
completely meaninglessly.

If you want to run a bunch of programs from the OEIS in one session you
probably have to do a Clear[All] after each one to avoid unexpected
interactions. For the five single letters that I mention, I can give
examples in the OEIS where they're used in such a way where one could
easily get confused as to whether it's a function or a variable, a more
fundamental problem than knowing what kind of function or variable it is.

It is utterly absurd to give a function pertaining to semiprimes the name o
or v. Just a few more characters would make it clearer. Examples:

* TermFunction - function that computes the nth term (respecting the
offset) nthSemiPrime[n]
* TermListByIndexFunction - function that computes the list of terms up to
the nth term semiPrimesUpTo[n]
* MembershipTestFunction - predicate function for testing membership,
returning True or False semiPrimeQ[n]

There is no mistaking semiPrimeQ[n] for a term list by index function
definition, whereas t or u or whatever single letter could very easily be
that or anything else.

Now, Eric, you've also noticed certain inefficiencies, like f[n_] := n^2;
Array[f, 50], which I wish was a completely fictional example. But that's a
whole other rant.

Al

On Tue, Nov 3, 2015 at 8:22 AM, Eric Rowland <rowland at lacim.ca> wrote:

> Lots of good comments.
>
> Yes, it is intended that the metadata be sufficient to programmatically use
> the associated code.  For example, a TermFunction should be an expression
> that can immediately be passed an argument.  A TermFunctionDefinition is a
> piece of code that defines a function, so there is some overhead required
> to extract the function name, but this isn't terribly difficult:
>
> In[1]:= Replace[Hold[A000108[n_] := (2 n)!/n!/(n + 1)!],
> Hold[_[functionname_[__], _]] :> functionname]
> Out[1]= A000108
>
> The labels are somewhat Mathematica-specific, since the notion of a pure
> function doesn't exist in all languages.  So in other languages there may
> only be TermFunctionDefinition labels and no TermFunction labels.  Or maybe
> we would use different labels entirely.
>
> Yes, putting metadata in comments takes up space on the page.  Charles has
> a great idea to display the metadata in the margin along with the
> MATHEMATICA heading.  An alternative might be to suppress the metadata from
> the human-readable version.  But either way, changing formatting on the
> site takes work, and if we wait for that then I'm afraid nothing will ever
> happen.  On the other hand, if we start adding metadata, then we will see
> whether we need different formatting, and if we decide we do then it will
> encourage us to add it.
>
> Since we designed the labels to be Mathematica-specific, they follow
> standard Mathematica naming conventions (no abbreviations, camel case).
> Everything you need to know is there.
>
> There are a couple problems with standardizing function names.  One is that
> it would require changing a lot (most?) of the existing code, rather than
> simply adding metadata to it.  (And if we are prepared to change most of
> the existing code, then ideally we would convert all the function
> definitions to pure functions and not have function names at all, since
> pure functions are programmatically much more flexible.)  Another is that
> it's more complicated to programmatically access the function you want, if
> the only information you have is the function name (see above).  If the
> program type is identified by a dedicated label, then you just check for
> the right label and you don't need to do any string processing.
>
> Eric
>
> _______________________________________________
>
> Seqfan Mailing list - http://list.seqfan.eu/
>



-- 
Alonso del Arte
Author at SmashWords.com
<https://www.smashwords.com/profile/view/AlonsoDelarte>
Musician at ReverbNation.com <http://www.reverbnation.com/alonsodelarte>



More information about the SeqFan mailing list