Re: OOPs!! When is a class not a class? (Re: Number/Specificality/Archetypes in Language)
From: | John Cowan <jcowan@...> |
Date: | Monday, September 27, 2004, 12:59 |
Pablo Flores scripsit:
> >From what you wrote, it seems to me that Pick Basic
> forces you to learn two operators where just one
> (overloaded) would be enough.
[snip]
> I agree that a good programming language should
> not be as paternalistic as to assume that, when you
> wrote '2' + '2', you actually meant 2 + 2...
It's a matter of point of view. If you conceive of concatenation
as "string addition" (in the same way that we conceive of integer
and floating-point addition as being "the same thing", though to the
CPU they are utterly different), then it makes sense to use the same
operator for them. But if you conceive of concatenation and addition
as two different things, it makes sense to use two different operators.
In the latter case, it further makes sense (in a dynamically typed
language, anyhow), when asked to add strings or concatenate numbers,
to coerce the operands to numbers or strings respectively.
In Pascal, "and" and "or" (the & and | type, not && and ||, which
Pascal does not have) are conceived as "Boolean multiplication" and
"Boolean addition" respectively, and are consequently written "*" and
"+". This cannot be done in the C-influenced languages, because C
has no separate boolean type, and so separate operators were needed
(and also perhaps because anglophones often pronounce "+" as "and",
which would be very confusing in this context).
ObDigression: I've always liked Ada's solution for & and | vs. && and ||.
Ada uses keywords rather than symbols in most situations, and so writes
"and" and "or" for the simple operators; the relationship of the shortcut
operators to conditionals is explicitly recognized by writing "and then"
and "or else", and this makes a handy way to read && and || out loud in
C-derived languages.
me.give(you.money()) || !
--
Newbies always ask: John Cowan
"Elements or attributes? http://www.ccil.org/~cowan
Which will serve me best?" http://www.reutershealth.com
Those who know roar like lions; jcowan@reutershealth.com
Wise hackers smile like tigers. --a tanka, or extended haiku