python without OO
Jeff Shannon
jeff at ccvcorp.com
Tue Jan 25 20:43:20 EST 2005
Davor wrote:
> [...] what I need that Python has and bash&dos don't is:
>
> 1. portability (interpreter runs quite a bit architectures)
> 2. good basic library (already there)
> 3. modules for structuring the application (objects unnecessary)
> 4. high-level data structures (dictionaries & lists)
> 5. no strong static type checking
> 6. very nice syntax
But modules, lists, and dictionaries *are* all objects, and one uses
standard object attribute-access behavior to work with them.
> so initially I was hoping this is all what Python is about, but when I
> started looking into it it has a huge amount of additional (mainly OO)
> stuff which makes it in my view quite bloated now...
If you're basing your opinion of OO off of C++ and Java, then it's not
too surprising that you're wary of it. But really, the OO in Python
is as simple and transparent as the rest of the syntax. You don't
need to define your own classes if you don't want to -- it's quite
easy to write modules that contain only simple functions. A trivial
understanding of objects & object attributes is needed to use the OO
portions of the standard library. If you really want, you can still
dictate that your own project's code be strictly procedural (i.e. you
can use objects but not define objects).
> anyhow, I guess
> I'll have to constrain what can be included in the code through
> different policies rather than language limitations...
You mention elsewhere the fear of some developer with a 50-layer
inheritance heirarchy. That's not something that normally happens in
Python. Indeed, one of the tenets of the Zen of Python is that "flat
is better than nested". But more than that, it's just not necessary
to do that sort of thing in Python.
In statically typed languages like C++ and Java, inheritance trees are
necessary so that you can appropriately categorize objects by their
type. Since you must explicitly declare what type is to be used
where, you may need fine granularity of expressing what type a given
object is, which requires complex inheritance trees. In Python, an
object is whatever type it acts like -- behavior is more important
than declared type, so there's no value to having a huge assortment of
potential types. Deep inheritance trees only happen when people are
migrating from Java. ;)
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list