How clean/elegant is Python's syntax?
Michael Torrie
torriem at gmail.com
Thu May 30 19:30:34 EDT 2013
On 05/30/2013 12:18 AM, Steven D'Aprano wrote:
> In some ways, Python is a more pure OOP language than Java: everything in
> Python is an object, including classes themselves.
>
> In other ways, Python is a less pure and more practical language. You
> don't have to wrap every piece of functionality in a class. Python
> encourages you to write mixed procedural, functional and object oriented
> code, whatever is best for the problem you are trying to solve, which is
> very much in contrast to Java.
Depending on your understanding of what object-oriented means,
procedural and functional code is still object-oriented. In fact
modules (the "file") are in essence singleton objects that define
attributes, but in practice there can only be one instance of this
object (module). Seems like in Java a lot of code is needed to
implement singletons (factory, etc). module-level code (procedural
code) could simply be thought of as singleton initialization/constructor
code that's automatically run when the singleton is created, using
import or __import__().
At the function level, a simple function is still an object that
implements callable.
Python's implementation of OO isn't quite smalltalk pure, but it is much
more consistent than in Java or C++.
But yes, Python does not force you to shoe-horn your programming into
one particular pattern.
More information about the Python-list
mailing list