[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: another take on hackers and painters
At 11:52 AM -0400 5/23/03, Vadim Nasardinov wrote:
>Anton van Straaten wrote:
>>the different purposes. Proposal: add an operator ~+~, pronounced
>This goes against Perl's philosophy, which I would summarize as
>"programs must be easy for people to *write*, and only incidentally
>so for people to *read*". As Dan repeatedly pointed out, this is a
>totally correct approach in certain domans.
It's correct in any domain where all such programs saved
to disk are removed every 24 hours. I'm only half joking.
Auto coercions appear to have the effect that they make
single functions (such as '+') obey multiple protocols.
In my experience, this is a bad thing in the long run.
It muddies the contracts of what things are supposed to
do, and it makes programs hard to understand.
I used to write APIs that "did favors" like this a lot,
but over time I stopped doing this because:
- it was harder to document the behavior (this is always
a sign of poor design, in my opinion)
- it was harder to maintain the code
- users complained of buggy or inconsistent behavior
Simply removing these "favors" fixed all of these problems
with a single stroke.
Even mainstream books like "Writing Solid Code" discourage
writing functions with multiple contracts.
You might rightly ask why I don't rail against '1 + 2.5'
when I would rail against '1 + "2"'. It's because the
contract of '+' has not been messed up. + preserves all
of the mathematical properties I would expect, and the
domain and range are all numbers, which related to each
other in ways the numbers and strings are not.
By the way, including vector/matrix addition/multiplication
under the names '+' and '*' also gives me the willies,
tho' reasonable people might reasonably disagree. At the
very least, I would put these in their own "namespace".