python philosophical question - strong vs duck typing

D'Arcy Cain darcy at druid.net
Tue Jan 3 13:50:43 EST 2012


On 12-01-03 01:13 PM, Sean Wolfe wrote:
> Hello everybody, I'm a happy pythonista newly subscribed to the group.

Welcome.

> The question is, given this possibility, would this get us closer to
> being able to compile down to a language like C or C++?

That's "a" question.  "The" question is "do you want to?"  Since we 
already run in machine language (doesn't everything) then how can you be 
sure that introducing another layer will improve performance?

> What I am driving at is, if we are coding in python but looking for
> more performance, what if we had an option to 1) restrict ourselves
> somewhat by using strong typing to 2) make it easy to compile or
> convert down to C++ and thereby gain more performance.

Where is your bottleneck?  I have seldom found Python to be it. 
Remember, almost everything you run was written in C.  Python is just 
the glue that binds it all together.

Consider ls(1) (dir in Windows/DOS) for example.  If you need a 
directory listing you type that and get it pretty quickly.  Is there a 
bottleneck?  Yes, it's you.  The command can probably do all of its work 
much faster than you can type the command.  Now put the command into a 
script.  Entering the command is no longer the bottleneck.  It's now the 
time it takes to access the drive.  Do we care?  Probably not and if we 
did there's probably not much we can do about it.  Python is simply a 
more powerful and efficient way to get to that machine language in a script.

If you do have a pure Python function that is a bottleneck and you 
believe that C can solve it, you can always write just that part in C. 
However, run some tests first to make sure.  99% of the time you can fix 
it algorithmically or else it wasn't the bottleneck that you thought it 
was.  And if it is and no one has already written a module for it, you 
just found a project to contribute back to the community.  :-)

> It seems to be that accepting the restrictions of strong typing might
> be worth it in certain circumstances. Basically the option to use a

So few as to not be worth changing the language for, especially when C 
is always available if you need it.

Cheers.

-- 
D'Arcy J.M. Cain <darcy at druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
IM: darcy at Vex.Net



More information about the Python-list mailing list