Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109249

Re: Recommendation for Object-Oriented systems to study

From Gregory Ewing <greg.ewing@canterbury.ac.nz>
Newsgroups comp.lang.python
Subject Re: Recommendation for Object-Oriented systems to study
Date 2016-05-30 11:34 +1200
Message-ID <dr1cjkFbmafU1@mid.individual.net> (permalink)
References <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> <b42b93a5-7b4c-4492-8692-b99b369333c0@googlegroups.com> <201605291812.u4TI9dqP037317@mx0a-001b2d01.pphosted.com> <mailman.30.1464549450.1839.python-list@python.org>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Recommendation for Object-Oriented systems to study Ankush Thakur <ankush.thakur53@gmail.com> - 2016-05-29 07:42 -0700
  RE: Recommendation for Object-Oriented systems to study "Joseph Lee" <joseph.lee22590@gmail.com> - 2016-05-29 09:00 -0700
    Re: Recommendation for Object-Oriented systems to study Ankush Thakur <ankush.thakur53@gmail.com> - 2016-05-30 08:56 -0700
  Re: Recommendation for Object-Oriented systems to study Michele Simionato <michele.simionato@gmail.com> - 2016-05-29 10:49 -0700
    Re: Recommendation for Object-Oriented systems to study Terry Reedy <tjreedy@udel.edu> - 2016-05-29 14:29 -0400
      Re: Recommendation for Object-Oriented systems to study Ankush Thakur <ankush.thakur53@gmail.com> - 2016-05-30 08:57 -0700
        Re: Recommendation for Object-Oriented systems to study Terry Reedy <tjreedy@udel.edu> - 2016-05-30 15:01 -0400
          Re: Recommendation for Object-Oriented systems to study Ankush Thakur <ankush.thakur53@gmail.com> - 2016-05-31 10:52 -0700
            Re: Recommendation for Object-Oriented systems to study Terry Reedy <tjreedy@udel.edu> - 2016-06-01 05:22 -0400
              Re: Recommendation for Object-Oriented systems to study Ankush Thakur <ankush.thakur53@gmail.com> - 2016-06-03 10:28 -0700
    Re: Recommendation for Object-Oriented systems to study Alan Evangelista <alanoe@linux.vnet.ibm.com> - 2016-05-29 15:12 -0300
      Re: Recommendation for Object-Oriented systems to study Marko Rauhamaa <marko@pacujo.net> - 2016-05-29 22:42 +0300
      Re: Recommendation for Object-Oriented systems to study Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-05-30 11:34 +1200
        Re: Recommendation for Object-Oriented systems to study Ankush Thakur <ankush.thakur53@gmail.com> - 2016-05-30 08:59 -0700
      Re: Recommendation for Object-Oriented systems to study Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-01 22:44 -0700
        Re: Recommendation for Object-Oriented systems to study Alan Evangelista <alanoe@linux.vnet.ibm.com> - 2016-06-02 09:15 -0300
          Re: Recommendation for Object-Oriented systems to study Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-02 18:13 -0700
          Re: Recommendation for Object-Oriented systems to study Bob Martin <bob.martin@excite.com> - 2016-06-03 07:14 +0100
            Re: Recommendation for Object-Oriented systems to study Phuong Phan <p.h.phan2006@gmail.com> - 2016-06-03 18:07 +0900
              Re: Recommendation for Object-Oriented systems to study Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-03 09:17 -0700
  Re: Recommendation for Object-Oriented systems to study Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-05-30 14:14 -0400
  Re: Recommendation for Object-Oriented systems to study Sayth Renshaw <flebber.crue@gmail.com> - 2016-06-03 07:24 -0700
    Re: Recommendation for Object-Oriented systems to study Ankush Thakur <ankush.thakur53@gmail.com> - 2016-06-03 10:24 -0700

csiph-web