Is a language without interfaces a bad choice for teaching OOP (Python)? -
perhaps dated on information, going learn oop language, concepts, etc. wanted use dynamic. thought python read has no interfaces. isn't interface needs know learn oop concepts?
my thought python read has no interfaces.
well, can use interfaces in python. standard library has abc
module, , there third-party modules pyprotocols (and frameworks zope , twisted have own similar ideas).
the point aren't required, , aren't necessary. "wanted use dynamic"? that's means dynamic: functions take object right interface, without needing interface statically defined anywhere, less needing object statically declare supports interface.
so, when ask:
isn't interface needs know learn oop concepts?
the answer "no". interface needs know learn java-style oop, it's not needs know learn oop in general.
consider different angle: it's possible, not easy, javascript-style oop in python; in java, classes fundamental python live without. make python , java bad oo languages , javascript one? no; makes them different oo languages.
monkut wanted know "wtf interface???"
an interface (aka protocol, abstract base class, abstract type, …) type can used static and/or dynamic type checking and/or switching in same way class can.
so, what's of that? well, in theory, should never need inspect types—that's not part of zen of python, it's part of core oo dogma well—but in practice do. so, being able name abstract types, , declare class supports variety of different abstract types, can useful.
of course plain old classes, being able explicitly declare type abstract can readability , debugging. pep 3119 explains rationale in python-centric way.
but in languages java, there's 2 additional benefits.
first, if have static type checking, can't write single function can take, e.g., list, tuple, set, frozenset, or iterator. can write function takes iterable, , declare list, tuple, etc. provide iterable interface, , fine. (in language dynamic type checking, duck typing takes care of you—your code works object has __iter__
method returns behaves way expect to.)
second, if you've got static data member layout and/or vtable-style method override mechanism, multiple inheritance tricky. multiple inheritance useful. in java, interface class, no data members or method implementations, , can inherit many interfaces want, 1 class. gives java of benefits of multiple inheritance, without of problems. (in language dynamic data members , dynamic method lookup, long have sensible mro algorithm, python does, can of benefits of multiple inheritance without of problems.)
Comments
Post a Comment