PEP0238 lament

Steve Horne sh at ttsoftware.co.uk
Tue Jul 24 15:33:47 CEST 2001


On 23 Jul 2001 19:41:48 GMT, Marcin 'Qrczak' Kowalczyk
<qrczak at knm.org.pl> wrote:

>Mon, 23 Jul 2001 18:45:12 GMT, Grant Edwards <grante at visi.com> pisze:
>
>>>But ints *are* implicitly converted to floats when needed
>> 
>> Language design mistake.
>
>It allows to write code which increments a number of unknown type
>by one. How would you write it in your universe?

Well, in the Ada universe - where clarity, simplicity and reliability
(but not conciseness) were explicit language design goals - no
typecasts are ever done implicitly.

In Ada, 'velocity := distance / time' may well be an error - unless
you've make sure you have operators that deal in the right mixture of
types. The benefit happens when you have a temporary fit and type
'velocity := distance / velocity' or some such - if your types are set
up right, that's an error because the division operator for
distance_type divided by velocity_type should return time_type - same
as keeping track of the units in physics - and you can't assign a
time_type into a distance_type. The fact that all three types are
probably implemented with exactly the same numeric representation is
irrelevant.

Literals can be used for any type where the representation matches, so
incrementing is not a problem. There's some compile-time-only type for
'untyped' numbers as well, so you can name a value and more or less
treat it as a literal if necessary (an often misused feature - you
wouldn't believe the number of programs with the identifiers 'zero'
and 'one' defined).

-- 
Steve Horne
Home : steve at lurking.demon.co.uk
Work : sh at ttsoftware.co.uk



More information about the Python-list mailing list