voc icon indicating copy to clipboard operation
voc copied to clipboard

[Proposal] Have a Java inheritance chain for standard types implemented

Open uranusjr opened this issue 8 years ago • 3 comments

Currently (almost) all types inherit from org.python.types.Object. While this reflects the inheritance chain on the Python side (most types inherit from object), this makes the implementation unnecessarily difficult, and require a lot of duplicate code because we can’t really utilise Java polymorphism idioms, such as Generics and Interfaces. This is most problematic in collection types, but also poses a problem with other types.

One example is the List::extend implementation merged in #645—the whole if-else block is unnecessary if Generics can me used.

As @freakboy3742 mentioned in #486, the Java inheritance chain does not affect the Python inheritance chain. Since inheritance and interfacing is front and centre in Java’s OOP, we should use it.

Python provides a set of abstract base classes that can offers a good sense how the inheritance chain should look like. Some extra classes might be necessary (I think) to abstract the internal structures, but not much. This could probably be a beginning for solution toward #582.

uranusjr avatar Sep 05 '17 07:09 uranusjr

This is a very interesting idea. Interfaces certain seem like they could be very useful, as long as we can contain and prevent them from exploding in number with some careful design...

cflee avatar Sep 10 '17 09:09 cflee

This definitely looks like something worth exploring - although I suspect the devil will be in the details.

Have you got any concrete ideas for how to implement this? It is a case of picking features one at a time and interfacing/inheriting them until everything is cleaned up?

freakboy3742 avatar Sep 10 '17 14:09 freakboy3742

Not really, what I currently have in mind is to loosely follow the collection ABCs, implementing what we think is good along the way. Classes that can provide the most benefits right now IMO are Iterable (#645 and a lot of other similar code would benefit) and ByteString (Bytes and Bytearray rightly share most of their implementation). Another one I can think of is the number classes (#582).

uranusjr avatar Sep 10 '17 16:09 uranusjr