Why use Perl when we've got Python?!
ebohlman at netcom.com
Fri Aug 13 22:55:19 EDT 1999
John W. Stevens (jstevens at basho.fc.hp.com) wrote:
[quoting someone whose name was lost]
: > It is wrong from the Larry's principle that things that behave
: > differently should have different appearances.
: Then why doesn't Perl have two different operations for
: assign/reassign, vs. add to an array? A tiny little violation of
: Larry's principles, that.
Nope. "Behave differently" hear means "accomplish two different tasks."
Comparing two strings to see if they're equal lexically is not the same
task as comparing two strings to see if they're equal numerically.
Putting a particular value in a particular position in an array that
already holds a value *is* the same task as putting a particular value in
a particular position of an array that does not yet hold a value; the
only difference is in the internal details of how to accomplish it.
Of course, the OOically-correct way to handle the string comparisons is
to define a base class, ComparableString, and two subclasses,
LexicallyComparableSting and NumericallyComparableString, along with
polymorphic operators that understand which class they're comparing to
and apply the correct comparison method. But there are cases where you
may want to do *both* comparisons on a string, and to be OC you then have
to cast the string to the appropriate type; the Perlish way of picking
the operator director is IMHO easier and more maintainable; in my
experience, heavy casting makes code unreadable.
More information about the Python-list