# The following was supposedly scribed by
# Torsten Schoenfeld
# on Sunday 27 February 2005 10:12 am:
>> I still don't see the problem of using a proper namespace. Arguments
>> of length are not compelling. What's wrong with a descriptive name?
>
>I tried to explain this two times already. �If it doesn't convince
> you, well, there's nothing more I can do. �If you had ever used a
> module such as Gtk2 or Gnome2, you'd understand.
I'm all for brevity, but in what way to the Media::Gstreamer::* modules
need to have their own constructors which are independent of the
toplevel module? To put it another way, isn't there one module in the
set which will always be used?
If the answer is no, I think you have an architectural issue. If the
answer is yes, then a factory (as previously suggested) or other
autoloading method seems the best way to get brevity.
use Media::Gstreamer;
my $gst = Media::Gstreamer->new(%whatever);
my $clock = $gst->newClock(time());
my $index = $gst->newIndex();
my $struct = $gst->newStruct();
<rant>
The above is just an ill-planned example of how you could shorten the
constructor calls without rethinking your API. A good API would
include a healthy dose of DWIM and probably wouldn't involve explicit
creation of $struct.
If you really want it to emulate the C API, I think that's a misguided
design decision which far too many Perl modules have used for no good
reason. Why make a Perl binding if it isn't going to leverage the
strengths of Perl? Common irritations include passing all arguments as
lists (like line_intersection($x1, $y1, $z1, $x2, $y2... (It just plain
hurts to type it all.)) or thing($option, $usually_zero,
$nobody_ever_sets_this_variable, $but_we_need_this_one)) instead of
using data structures (perl makes it really easy to represent a line as
@a_line = ([0,0],[1,1,1]) and undef() == 0 should be on a poster on
your wall right next to the one that says \%options) and using
set_foo/get_foo/new_foo methods where foo => $foo or
$obj->foo()/$obj->foo($foo) would work.
</rant>
So, to reduce friction, you should go with Media::Gstreamer::* as both
the package and namespace names, then find yourself some magic to make
your code shorter. Perl has plenty of ways to make that magic happen,
and the tastiest ones probably involve stepping 17" to the left and
eliminating the need for anybody to ever call
Media::Gstreamer::Structure->new() by rethinking the problem in Perl
instead of as "python with glyphs."
Don't take any of this callousness personally, unless it helps you write
a better API. I've just spent the better part of a week swimming
through various existing modules and packages which all seem to have
some ugliness in them. TMTOWTDI has a very dark side and it most often
shows up in large projects.
--Eric
--
"The genius of you Americans is that you never make clear-cut stupid
moves, only complicated stupid moves which make us wonder at the
possibility that there may be something to them which we are missing."
-- Gamal Abdel Nasser
---------------------------------------------
http://scratchcomputing.com
---------------------------------------------