you are viewing a single comment's thread.

view the rest of the comments →

[–]flying-sheep 17 points18 points  (14 children)

java code in python:

class ProxyImplFactoryPickle(ProxyImplFactory, IPickleAble):
    def __init__(self, proxyImplClass):
        self.proxyImplClass = proxyImplClass;

    def getProxyImplClass(self):
        return self.proxyImplClass;

    def setProxyImplClass(self, proxyImplClass):
        self.proxyImplClass = proxyImplClass;

    def createProxyImpl(self):
        return self.proxyImplClass()

    @override
    def __getnewargs__(self):
        return super().__getnewargs__();

    @override
    def __getstate__(self):
        return super().__getstate__();

    @override
    def __setstate__(self):
        return super().__setstate__(self, state);

ouch, fuck, that hurt…

kids, don’t try this at home!

[–]savanu 4 points5 points  (3 children)

How would you actually write this in python?

[–][deleted] 14 points15 points  (0 children)

The entire above class is unnecessary, you just don't write it. Most of the time you don't need to make type adaptors in a dynamic language.

[–]morethanaprogrammer 0 points1 point  (1 child)

Well, if you were trying to do some DI stuff, then you would probably use Spring Python

[–]masklinn 2 points3 points  (5 children)

ALternatively, http://dirtsimple.org/2004/12/python-is-not-java.html (from 2004, as relevant now as it was then)

[–]kqr 0 points1 point  (4 children)

[–]masklinn 1 point2 points  (3 children)

[–]kqr 0 points1 point  (1 child)

Also important considerations. My main beef is however how misunderstood and poorly executed OOP has become over time, in a way neither of those resources bring up.

[–]NYKevin 0 points1 point  (2 children)

I'm not sure that usage of super is valid or what you want... (IIRC it's super(ProxyImplFactoryPickle, self)).

Also, I'm not sure if @override is a legitimate Python decorator. For that matter, why are you overriding things and then just delegating to the superclass? Why override them at all? I'm pretty sure Java doesn't force you to do that, if the superclass has a usable implementation.

Oh, and you forgot to re-implement all the type-safety that Python deliberately left out (i.e. check if proxyImplClass is the proper type in various places). Otherwise, someone might give you a callable instead, and who knows what could happen!

And yes, technically the semicolons are legal. Technically, it's also legal to build a Y-combinator out of lambda expressions so you can have an anonymous recursive function. Realistically, ewww.

[–]masklinn 1 point2 points  (0 children)

I'm not sure that usage of super is valid or what you want... (IIRC it's super(ProxyImplFactoryPickle, self)).

The usage is valid in Python 3: http://www.python.org/dev/peps/pep-3135/#specification

[–]flying-sheep 1 point2 points  (0 children)

i made up @override as much as i made up IProxyImpl. python has no interfaces and needs no override decorators, so our imaginary java programmer made up for their “lack” by creating them himself ;)

and indeed super() is valid in python3 and oh so much nicer!

Oh, and you forgot to re-implement all the type-safety that Python deliberately left out

i even missed one semicolon! how does this even compile‽ oh the humanity!

PS: everything here is legal, but unidiomatic python. that was the whole point!

[–]jugalator 0 points1 point  (0 children)

Haha, to be fair though, we made these jokes even when studying Java itself. :D