Strong typing implementation for Python

Michael Torrie torriem at gmail.com
Mon Oct 12 12:08:45 EDT 2015


On 10/12/2015 02:47 AM, John Michael Lafayette wrote:
> Now that Python has static type checking and support for IDE auto-complete
> (PEP 484?), I beg you to please use it. In your standard library, in your
> production code, in everywhere. I cannot type without auto-complete.
> 
> I know that sounds ridiculous, but I have been coding on a daily basis for
> the last four years and I cannot recall the last time I actually typed out
> a variable or function name without auto-complete typing it for me. To me,
> java.net.DatagramSocket isn't "DatagramSocket". It is "Da" + Ctrl + Space +
> Enter (auto complete). I literally memorized the number of characters I
> have to type for auto-complete to guess the variable name and then I only
> type that many characters. For me, typing without auto-complete is like
> doing surgery with a kitchen knife. It's messy and error prone and I make
> lots of mistakes and have to try twice as hard to remember the actual names
> of variables instead of just whatever they start with.

I haven't used Java in many years now, but it sounds like it's an awful
experience to use if auto-complete is such a requirement to get anything
done.

> You don't understand because you actually know what all the function
> names are and you don't have to constantly hover over them in
> auto-complete and pull up their documentation to figure out how to
> use them. But I do. And for me, without auto-complete, the learning
> process goes from actively querying the IDE for one documentation
> after another to having to minimize the IDE and Google search for
> each and every function and module that I"m not familiar with.
> Auto-complete literally cuts the learning time by more than half.

Of course I don't know all the function names by heart.  But in several
years I haven't had to either.  A few that I use regularly are easy to
memorize.

Not sure what you mean about having to minimize anything.  If an IDE has
to be kept full-screen all the time then I would find them to be a
significant handicap.  I have a windowing system for a reason!  I can
count on one hand the number of times I've maximized a window in the
last few years.

As others have said the standard library docs are quite good, and it's
not hard to keep them up next to my programming window.  Also Python can
help document itself.  A vital tool for any Python programmer is an
interactive Python session.  It's often easier to query the object I'm
working with directly to find what methods it supports and the
parameters it expects.  Get familiar with the Python interactive mode
and with basic calls like dir() and help().

Also many Python editing environments do support basic completion.
However completion is actually very difficult to implement in a static
manner because Python is so dynamic.  I can import any standard library
module and rename it as needed.  Since some modules have longer names
that I don't want to always type and since importing all of a module's
symbols into the global namespace is really not a good idea, I might do
something like

import BeautifulSoup as bs

Now I can refer to any BeautifulSoup symbols using the prefix bs.  That
isn't impossible for an IDE to track, but it is harder.

If you can set aside your prejudices (static typing) and learn idiomatic
python I think you'll have a great amount of fun and you'll find that
even without the same level of auto completion that you'll be able to
develop quite a bit faster than with Java.  There's a good book called
Fluent Python that can show you how idiomatic Python can really benefit
you.  Another good one is "Effective Python."



More information about the Python-list mailing list