Recommendation for Object-Oriented systems to study

Gregory Ewing greg.ewing at canterbury.ac.nz
Sun May 29 19:34:11 EDT 2016


Alan Evangelista wrote:

> if the interest is learning OOP concepts (and not OOP in Python), IMHO 
> Java is better.

The problem with this is that if you're not careful you'll
end up learning a lot of cruft that is irrelevant to Python.
There's no clear distinction in Java between things that
are essential to OO and things that are only there to
support its rigid statically-typed view of the world.

> - Java forces everything to be implemented in OO model (classes)

Actually, it doesn't do that any more than Python does.
Static methods are really stand-alone functions; they just
happen to live in the namespace of a class. In other words,
all Java does in this area is confuse things by conflating
modules with classes.

> - Java widely uses interfaces and abstract classes. Python has not the 
> concept of interface, as it favors EAFP
> and duck typing instead of creating base classes which establish 
> contracts.

And this is one of the important things to understand if
you want to write Python programs, rather than Java programs
encoded in Python.

> Python also allows multiple inheritance,
> which is *usually* a bad idea, unless the base classes are interfaces.

Actually the best use of multiple inheritance in Python is
to factor out *functionality*, more or less the opposite
of what Java allows. In fact, that goes for inheritance of
any kind; you only need it if you want to share functionality
from the base class. This is very different from Java,
where considerations of static interface checking dominate
everything.

> - In Java, interface/implementation separation is *usually* a bigger 
> concern (eg getters and setters
> are common in Java code, rare in Python code) .

That's because you don't *need* them in Python, since you
can always turn an attribute into a property at any time
without affecting calling code. You can't do that in Java,
which is the only reason you see so many getters and setters.
If you think you might ever need them, you have to start
out with them from the beginning.

So in summary, I wouldn't recommend learning Java as a
precursor to learning Python OO. You'll just confuse yourself
and pick up a lot of bad habits that you'll have to unlearn
later.

-- 
Greg



More information about the Python-list mailing list