a couple of questions: pickling objects and strict types

Chris Angelico rosuav at gmail.com
Fri Apr 5 20:31:35 EDT 2013


On Sat, Apr 6, 2013 at 5:59 AM, Littlefield, Tyler <tyler at tysdomain.com> wrote:
> I come from a c++ background; though it doesn't help in catching runtime
> errors, being able to compile a program helps catch a lot of syntax errors.

Syntax errors you'll still catch just by attempting to load up the
module in any way:

def foo():
  if True   # oops, no colon
    pass

You don't need to execute that particular line of code to get the
error. But there are a whole lot of errors that a C++ compiler would
catch that Python leaves until run-time, such as variable name
misspellings, data type mismatches, etc, etc... however, this is part
of what gives Python its flexibility. In fact, a lot of things that
would be errors in C/C++ are actually quite legal and useful in
Python.

The one area that I would prefer the C model, though, is declared
variables vs freely-usable names. I prefer the Python notion of
"names" rather than "variables" (the difference takes a lot of words
to explain, but it makes VERY good sense - in a high level language),
but I do like the infinite nesting of scopes and simple catching of
misspellings that the declarations give. Effectively, what I'd like to
see is a declaration "local foo" instead of Python's choice of "global
foo" - with the caveat that globals can be read, but not written,
without that declaration. I think it's clearer and cleaner to declare
all locals. But that's a small matter.

ChrisA



More information about the Python-list mailing list