On Mon, 13 Jan 2003, Matthew Simon Cavalletto wrote:

> >> What's the benefit of making this distinction between core and
> >> "other" formats?
> >
> > Because "core" parsing would be available simply by doing:
> >   use DateTime;
>
> We can move the parsing to format modules and load them automatically.

Sure, that's possible too.  The real question is whether or not parsing
requires anything beyond doing "use DateTime".

> > It's really a question of whether or not users must load another
> > module to do parsing, that's all.
>
> The suggestion on the table is that even the "core" parsing be placed
> in another package, but that this be transparent to end-users.

But that's not my concern.  I _don't_ want to discuss implementation of
this.  I want to talk about the API!

> > Actually, I have some ideas for this. [...] the parsing modules would
> > just add methods to the DateTime namespace.
>
> Ick -- what's the advantage of doing it this way?
>
> It strikes me as a lot more logical to keep those methods in their own
> namespace and simply call them when needed.
>
> Looking at the two alternatives, does the second really seem clearer?
>
>    use DateTime;
>    my $dt = DateTime->new( 'MySQL' => $mysql_dt );
>    print $dt->to_string( 'MySQL' );
>
>    use DateTime;
>    use DateTime::Parse::MySQL;
>    my $dt = DateTime->from_mysql_datetime( $mysql_dt );
>    print $dt->to_mysql_string();

Um, yeah, the second is _much_ clearer.  And its less error prone as well!

If I mis-type 'MySQL' as 'Mysql' then what is DateTime supposed to do?
And how is DateTime->new supposed to know about all the myriad parameters
that would exist with your suggestion anyway?  If it finds an unknown
parameter, should it call "DateTime::Parse->$param()"?  What if a specific
parser needs _two_ params?

Your first option is not on the table.  The options on the table are:

  use DateTime;
  use DateTime::Parse::MySQL;
  my $dt = DateTime->from_mysql_datetime( $mysql_dt );
  print $dt->to_mysql_string();

or

  use DateTime;
  use DateTime::Parse::MySQL;
  my $dt = DateTime::Parse::MySQL->new_datetime( $mysql_dt );
  print DateTime::Parse::MySQL->mysql_datetime( $dt );

Frankly, I think the first one is a lot easier to use and makes more
sense.  It's the decorator pattern without the dispatching overhead!


-dave

/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/

Reply via email to