Leviathan has asked for the wisdom of the Perl Monks concerning the following question:
Hello fello monks,
I'm writing Perl bindings for Etk, a toolkit for the new Enlightenment Foundation Libraries (link).
The bindings are now almost completed, and I'm now trying to work on an easy to use API for perl.
As an example, in Etk there are different functions to create a button widget:
Etk_Widget *etk_button_new(); Etk_Widget *etk_button_new_with_label(const char *label); Etk_Widget *etk_button_new_from_stock(Etk_Stock_Id stock_id); // Etk_S +tock_Id is an enum
Here is my translation of this into the perl module:
sub new { my $class = shift; my $self = $class->SUPER::new(); if(@_ == 1) { my $thing = shift; $self->{WIDGET} = $thing =~ /\D/ ? Etk::etk_button_new_with_label($thing) : Etk::etk_button_new_from_stock($thing); } else { $self->{WIDGET} = Etk::etk_button_new(); } bless($self, $class); return $self; }
As you can see, I'm trying to stuff different calls inside the same perl method in the spirit of DWIMmery.
Similarly, for example, there's the tree sorting callbacks, it acts differently based on what is passed ar ound. Example:
$tree->Sort( \&sort_func, $asc, $column); # the same routine but without a coderef works differently $tree->Sort(NUMERIC, $asc, $column); # where NUMERIC is a constant, and thus the sorting is done in C to ma +ke it faster and avoid the roundtrip to perl.
Now, problem is that one of the developers of the Etk library is saying that this is a bit confusing for t he user, so I'm asking you fellow monks:
P.S: Anyone interested in checking the code out, it's in CVS in the enlightenment reposit ory accessible from the enlightenment website. It's in the proto/etk-perl module (Note that you need to compi le proto/etk for this to work)
Thanx for your comments and replies.
--
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question about module interface style
by Corion (Patriarch) on Jul 22, 2006 at 15:15 UTC | |
|
Re: Question about module interface style
by Tuppence (Pilgrim) on Jul 23, 2006 at 01:13 UTC | |
|
Re: Question about module interface style
by Aristotle (Chancellor) on Jul 22, 2006 at 15:12 UTC | |
|
Re: Question about module interface style
by eyepopslikeamosquito (Archbishop) on Jul 22, 2006 at 22:25 UTC | |
by tye (Sage) on Jul 23, 2006 at 17:05 UTC |