Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of super in ptyhandler.py #5

Open
giselher opened this issue Mar 20, 2012 · 5 comments
Open

Usage of super in ptyhandler.py #5

giselher opened this issue Mar 20, 2012 · 5 comments

Comments

@giselher
Copy link
Contributor

As said in the meeting the code is written with old style classe in mind and super should be only be used in new style classes.

Link to the code line: https://github.com/rainerf/ricodebug/blob/master/src/helpers/ptyhandler.py#L33

Use cases for super from the python 2.7 Documentation (http://docs.python.org/library/functions.html?highlight=super#super)

There are two typical use cases for super. In a class hierarchy with single inheritance, super can be used to refer to parent classes without naming them explicitly, thus making the code more maintainable. This use closely parallels the use of super in other programming languages.

The second use case is to support cooperative multiple inheritance in a dynamic execution environment. This use case is unique to Python and is not found in statically compiled languages or languages that only support single inheritance. This makes it possible to implement “diamond diagrams” where multiple base classes implement the same method. Good design dictates that this method have the same calling signature in every case (because the order of calls is determined at runtime, because that order adapts to changes in the class hierarchy, and because that order can include sibling classes hat are unknown prior to runtime).

@rainerf
Copy link
Owner

rainerf commented Mar 20, 2012

For Python 3 compatiblity, the whole codebase should be converted to use new-style classes. This should not be too hard to do, I hope.

@giselher
Copy link
Contributor Author

I still prefer to use usual inherit method instead of super, because it not only looks nicer but you don't have to worry about the downsides of super.

For reference:

@rainerf
Copy link
Owner

rainerf commented Mar 20, 2012

New-style classes have been introduced in Python 2.2, released in 2001 (!), and old-style classes will be removed with 3.0. Searching the web, I could not find any real downsides of new-style classes, other than some people using them incorrectly and some more or less constructed examples involving multiple inheritance. Is there anything I am missing?

The use of new-style classes seems to be encouraged over old-style classes, see for example:

@giselher
Copy link
Contributor Author

It is fixed in this commit: f7fa7a1

@rainerf
Copy link
Owner

rainerf commented Mar 21, 2012

As a short-term solution, plugins/Navigation/NavigationPlugin.py still needs to be fixed as it includes the same construct as ptyhandler.py did.

For the longer-term solution, I still think that new-style classes are the way to go. super()'s caveats seem to be very much tied to multiple inheritance, which should not be a problem in our case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants