Static typing [was Re: Python and the need for speed]

Chris Angelico rosuav at gmail.com
Sun Apr 16 08:28:06 EDT 2017


On Sun, Apr 16, 2017 at 8:55 PM, bartc <bc at freeuk.com> wrote:
> On 16/04/2017 05:27, Steve D'Aprano wrote:
>>
>> On Sat, 15 Apr 2017 11:55 am, Rick Johnson wrote:
>>
>>> apparently, the py-devs believe we
>>> only deserve type declarations that do nothing to speed up
>>> code execution (aka: type-hints), instead of type
>>> declarations that could actually speed up the code. Go
>>> figure!
>>>
>>> I'm not a fan of forced static typing, but i am a fan of
>>> optional static typing.
>>
>>
>> Are you aware that optional static typing CANNOT be used for optimization?
>>
>> Since it is *optional*, it is only a hint, not a fact. You can tell the
>> compiler that you believe that n will be an int, but it's not guaranteed.
>
>
> No, Rick distinguished between hints, and actual declarations. It doesn't
> matter if the latter are optional.
>
> I played around with this at one time. All variables were of type 'variant',
> unless they had an explicit type declaration.

All of this is ignoring one very important point: subclassing. If I
declare a variable "int", can it or can it not accept a subclass of
int? Hint: neither answer is correct for the general case.

ChrisA


More information about the Python-list mailing list