[GAP Forum] Packages and global functions

Yevgen Muntyan muntyan at tamu.edu
Sat Apr 28 23:37:05 BST 2007


Laurent Bartholdi wrote:
> Dear Yevgen, dear forum,
>
> I have written a package that deals with 'automata groups', called
> "FR" (available on my webpage

Last time I tried it wasn't available. There was a link named something
like "frautomata.tar.gz" which you clicked and it said something like
"email me if you actually want it" (wording is not precise).

> ) and can explain a few of the design
> decisions I took. Either the remarks below will be helpful to you, or
> someone from the forum will correct me.
>
>> Should packages use operations as much as possible? It sounds
>> sensible since methods can be overridden as one wishes, and
>> operations with the same name can be declared for different
>> types safely. It doesn't solve the problem with category names
>> of course, but that's easier to deal with - a category with obscure
>> name is fine as long as user doesn't have to type it in (unlike
>> actual methods which are going to be used by a user).
>
> It seems that too much overloading causes performance loss. Therefore,
> it's good practice, if you know in advance which method will be used,
> to call the right one immediately.

I actually have never had problems with this. Method lookup is generally
lightning fast, and I haven't seen anything in GAP working slowly
because of overloading. If you multiply something million times then
perhaps it's faster to use some MultiplyIt function than multiplication
operator; but then if you multiply something million times you probably
want to avoid multiplication completely. In any case it's a separate
problem. I do believe slowdown may be caused by overloading, i.e. blind
"make everything operations" is not a sensible approach. But, just as you
say below, if something needs to be fast, it can be called
appropriately and used internally. The public API is what causes
name clashes, and that should use operations more.

> Therefore, e.g., automata have a
> 'Degree'. I have installed a method called 'DegreeAutomaton', which is
> used inside my code. For convenience of the user, I have also
> overloaded the general 'Degree' method. The idea is that a method
> lookup is inexpensive for a user, but may be costly within a
> subroutine.
>
>>
>> And related to this is real question, about namespaces. Are there
>> some plans to implement something like that in GAP? Some
>> method to separate names in a package would be awesome.
>> At the moment there are about million global names, and you
>> never know what your package will conflict with.
>
> I have created a single global variable 'FR_LOCAL', which is a record.
> this record contains all the local functions and variables of my
> subroutines.
This approach is very inconvenient, it makes code uglier, and you lose
completion in GAP (I do use such a thing for various things indeed).
Still, it doesn't help at all for public interface: you have to create 
categories
in global namespace (not too bad, since you can use obscure names),
and public functions have to be in global namespace, which is a real
problem, since names should be nice. E.g. 'automata' package grabs
lot of nice names. Problems with different versions of GAP are a normal
thing - new version brings new problems. It's not very hard problems,
usually easy to solve (== rename what needs to be renamed), but they
happen (naturally) at bad moments, when user gets the package and
starts GAP.

I am currently thinking what I like more: using prefixes like 'AG' 
everywhere
or ignoring the problem completely. The latter isn't going to work nicely,
but the former is ugly. Not sure what I am asking for here, but anyway,
exchanging ideas is never bad :)

Best regards,
Yevgen



More information about the Forum mailing list