Strong typing implementation for Python

Bartc bc at freeuk.com
Mon Oct 12 13:10:47 EDT 2015


On 12/10/2015 16:47, Michael Torrie wrote:
> On 10/12/2015 07:30 AM, Bartc wrote:
>> On 12/10/2015 03:45, Michael Torrie wrote:

>>> C++ introduced it a while ago (C++11), and D has had it from the
>>> beginning.  Even lowly FreeBasic has it.
>>
>> [I'm] surprised Basic needs it. The last time I looked, $A was a string,
>> %B an integer, and C a number. Type inference wasn't hard!
>
> Back in the day this was certainly true.  Most modern Basic dialects are
> more C-like in their declarations.
>
>> (And trying Freebasic, it insists on variables being declared anyway.
>> It's rather like C but with Basic syntax.)
>
> FB could be considered C-like with a Basic syntax, yes, but with dynamic
> strings and dynamic arrays.  This idea of being c-like makes FB kind of
> interesting but uninteresting at the same time.  Kind of hard to come up
> with a good reason to use it for something, especially when a dynamic
> language like Python, combined with C, is so flexible.

I suppose one reason is that it is easy to get up to speed with little 
effort, with something that is friendlier and a little higher level than 
C. Actually, I was pleasantly surprised at its capabilities.

(Example, calling fib(40) on the example below took 90 seconds on Python 
3.4, 11 seconds with PyPy, but only 1.8 seconds running the equivalent 
with FreeBasic:

  def fib(n):
    if n<2:
      return n
    else:
      return fib(n-2)+fib(n-1)

There are doubtless all sorts of ways of getting that sort of speed in 
Python, but it's something extra to be researched and to do and could 
require using an auxiliary language. Maybe there are too many possible 
ways which is another problem.)


-- 
Bartc





More information about the Python-list mailing list