http://qs321.pair.com?node_id=359718


in reply to How to make Win32::API easy to use

Does this type of simplification come from thinking like "the users", or am I just strange? Does this seem like a huge improvement to others? Anyone else felt "from the beginning" that Win32::API should be creating code refs, like that was the "natural" interface to provide?

I totally agree. A similar example for me is this from DBI:

$rc = $sth->bind_col($col_num, \$col_variable); $rc = $sth->bind_columns(@list_of_refs_to_vars_to_bind);

Ive never understood why that isnt:

$rc = $sth->bind_col($col_num, $col_variable); $rc = $sth->bind_columns(@list_to_bind);
As inside it could easily be:
my ($col_num)=@_; my $col_variable=\$_[1];
or
my @refs=map { \$_ } @_;

---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi


Replies are listed 'Best First'.
Re^2: How to make Win32::API easy to use
by tye (Sage) on Jun 02, 2004 at 20:56 UTC

    This hits on a difference in our "Perl views" (like "world views") that has come up before. I find aliases in Perl to be a special case and so I prefer to avoid them except in certain situations.

    I guess my heuristic is to avoid using them except across very short distances. The distance between the call to bind() and the definition of sub bind is pretty big, if you look at it one way.

    However, Perl's read sets a precedent that I sometimes follow and this case is close enough that I could certainly make arguments that it would an appropriate use here. But I also see two reason why someone wouldn't do this. The first is avoiding user surprise as I tried to explain briefly above (and probably failed).

    To make it more concrete, we don't have (w/o using C code not built into Perl) the ability to do:

    my( $name, $dob, $salary ); my @arrayOfAliases= ...( $name, $dob, $salary ); ...->bind_columns( @arrayOfAlises ); # nor my( $name, $dob, $salary ); my %colMap= ( Name => aliasOf($name), DOB => aliasOf($dob), Salary => aliasOf($salary), ); ...->bind_columns( @colMap{@colNames} ); # nor ...->bind_columns( map ... );

    so using aliases in your API restricts how people can use your API. (And I don't think my last example could be used even if you allow for a module including C code.)

    The second reason is "comfort" of implementation, which I see fits exactly the "not thinking of your users" problem I brought up.

    In Perl4 we had globs. In Perl5 we got references. In Perl6 we'll finally get full control over aliases and so they'll finally be acceptable to me to use in more general ways (I suspect).

    - tye