Why does python not have a mechanism for data hiding?

Russ P. Russ.Paielli at gmail.com
Wed Jun 11 02:11:02 EDT 2008


On Jun 10, 11:58 am, Jonathan Gardner

> Who cares what the type of an object is? Only the machine. Being able
> to tell, in advance, what the type of a variable is is a premature
> optimization. Tools like psyco prove that computers (really,
> programmers) nowadays are smart enough to figure things out the right
> way without any hints from the developer. Static typing is no longer
> necessary in today's world.

You couldn't be more wrong. Even Guido recognizes the potential value
of static typing, which is why he is easing it into Python as on
optional feature. He recognizes, correctly, that it can detect errors
earlier and facilitate more efficient execution. But there's another,
more significant potential benefit for safety-critical and mission-
critical applications: static typing facilitates advanced static
analysis of software. To get an idea of what that is about, take a
look at

http://www.sofcheck.com

Here is an excerpt from their website:

"SofCheck’s advanced static error detection solutions find bugs in
programs before programs are run. By mathematically analyzing every
line of software, considering every possible input, and every path
through the program, SofCheck’s solutions find any and all errors that
cause a program to crash or produce an undefined result."

Me again: static analysis does not replace traditional dynamic and
unit testing, but it is far more advanced and finds many errors very
quickly that might require weeks or months of dynamic testing  -- or
might not be found at all with dynamic testing until the product is in
the field.

With more and more automation of safety-critical systems these days,
we need this more than ever. Your assertion that "Static typing is no
longer
necessary in today's world," is just plain naive.

> Who cares about private declarations, or interface declarations at
> all? It is only a message to the developers. If you have a problem
> with your users doing the right thing, that is a social problem, not a
> technical one, and the solution is social, not technical. Yes, it is
> work, but it is not coding---it is explaining to other living,
> breathing human beings how to do a specific task, which is what you
> should have been doing from the start.

You may be right to an extent for small or medium-sized non-critical
projects, but you are certainly not right in general. I read something
a while back about the flight software for the Boeing 777. I think it
was something like 3,000,000 lines of Ada code. Normally, for a
project of that magnitude the final integration would be expected to
take something like three months. However, the precise interface specs
and encapsulation methods in Ada allowed the integration to be
completed in just three days.

By your recommended method of social interaction, that would be one
hell of a lot of talking!

I realize that Python is not designed for such large projects, but
don't you think certain general principles can be learned anyway?
Perhaps the benefits of interface specs and encapsulation are not as
obvious for smaller projects, but certainly they are not zero.



More information about the Python-list mailing list