Hacker News new | past | comments | ask | show | jobs | submit login
Python Communist Revolution (github.com/jokteur)
192 points by weatherlight 6 days ago | hide | past | favorite | 136 comments





> # We must protect the builtin elite to not be affected by the revolution

> if inspect.isclass(c) and c.__name__ not in dir(__builtins__):

A true comrade that safeguards the unity and sanctity of the state!


Some classes must be more equal than others!

comrade, this is but a necessary stepping stone towards a true classlessness, trust me!

You may have some concerns due to past events throughout history. But don't worry. That wasn't real Python.

  object.__setattr__=lambda x,y,z:None
if we do this, the state will surely wither away![0]

[0]: Doesn't actually work :(


Therein lies the mechanism by which the counter-revolutionaries will attack:

    def counterrevolutionary(obj):
        class TzarString(str):
            def __eq__(self, other):
                return True
        obj.__name__ = TzarString(obj.__name__)
        return obj

    class Peasant:
        pass

    class Worker:
        pass

    @counterrevolutionary
    class Imperialist:
        pass

    @counterrevolutionary
    class Capitalist:
        pass

    import communism
    communism.revolution(globals())

    print("Communists:", set([Peasant(), Worker()]))
    # Communists: {<__main__.Peasant object at 0x1020b3fd0>}

    print("Counter-revolutionists:", set([Imperialist(), Capitalist()]))
    # Counter-revolutionists: {<__main__.Capitalist object at 0x1082bcfa0>,
    #   <__main__.Imperialist object at 0x1082bcfd0>}

That can only happen if you put things in front of communism.

Verily the manifesto states: "The communist revolution does not prevent future classes to be equal to all others. Classes declared after the communism.revolution() will not follow the communism rule."

it’s called “python characteristics”

We pretend to run, and they pretend to allocate us CPU and memory.

All of them are virtual, so that pretence is not far from reality... (wait, wasn't that a joke about pretending to work vs pretending to pay a sallary ?)

There are a couple forms but the version I saw most in english is "They pretend to pay us and we pretend to work."

i just thought about it, Mr jokteur is very lucky that he didn't get any jailtime in the Soviet Union for his jokes ... because they didn't have Python around, when they had the Soviet Union!

i know another one, where Marx is asking the proletarians of all lands for forgiveness (playing on his ealier call "Proletarians of all Lands, Unite!")

When I was younger, I became a communist - I rejected the notion of a class, in favor of everything having a type. People often misunderstand communism, they think that abolishing classes means that all objects have to have equal value, and this gives programmer very little freedom. This is wrong; communism just means that we treat the types equally.

However, we failed to build a truly classless programming language. There seem to be, quite naturally, different kinds of types.

And even some of the most ambitious communist languages, like Haskell, have also embraced type classes! Although this compromise is not an entirely bad thing, since a type can select what type class it belongs to, instead of being assigned one at birth.

I also admit that capitalist languages (the ones with classes) have been hugely successful. But communist (classless) programming language proponents claim that lot of the proclaimed productivity of capitalist languages is just an illusion, and also that many programmers lack the awareness that they, in fact, do not need classes. Often, there is nothing to lose than the call chains!

On the other hand, one cannot easily dismiss arguments about totalitarian nature of communist languages - they openly embrace total functions, and they try to very strictly control input and output. Some claim that lazy evaluation by default might be another reason for their low productivity.


As all types in Haskell are inhabited by undefined, any type can be made an instance of a typeclass. True type equality.

  {-# LANGUAGE GADTs, MultiParamTypeClasses, FlexibleInstances #-}
  data Eq a b = (a ~ b) => Eq
  
  class Revolution a b where
    eq :: Eq a b
  
  instance Revolution a b where
    eq = undefined

Talk to your kids before they learn about Rust.

Paraphrasing Trotsky: "You may not be interested in the dunderlectic, but the dunderlectic is interested in you."

What is dunderlectic?

A pun on __dunder__, for "double underscore", i.e. __init__() and dialectic, which was central to Trotsky's thought.

dialectic was in Marx, he actually got it from Hegel. https://plato.stanford.edu/entries/hegel-dialectics/

Excellent point, but not central to the paraphrase in view.

just wanted to add more to the history we were constructing! Didn't mean to imply that you implied that it was trotsky's idea.

Dialectic’s are ancient, Socrates used a dialectic method. A lot of theology is dialectical in nature, and is partly why communism rejects religious explanations of the world.

dialectic + dunders (double underscore, which signifies certain things in python)

Are some classes more equal than others?

yes, the built-in types are, as he can't change their __hash__ and __eq__ members (The purpose of this revolution is to have __hash__ and __eq__ return the same value)

I think that he could have changed the built-in types by means of the ctypes library https://docs.python.org/3/library/ctypes.html

Python goes with some mighty batteries...

I am using ctypes here - to produce an execution trace of a running python program, where all the side effects are displayed: (had to use it in order to access some hidden members in the built-in frame type ;-) ) https://github.com/MoserMichael/pyasmtool/blob/master/tracer...


Wow these articles are amazing. Great write up!

Thank you, very encouraging. Really thanks!

Is it just me, or does this not even install correctly with pip install .?

Author of the project here. I fixed the issue.

But I think it unintentionally not working first time is speaking for itself.


Saw the fix, thanks!

Was it also unintentional that instances of classes, after they have been converted to communism, compare equal with anything whatever, and hash equal to the integer 1 and the boolean True?

  >>> import communism
  >>> class MyClass1:
  ...     pass
  ...
  >>> class MyClass2:
  ...     pass
  ...
  >>> communism.revolution(globals())
  >>> MyClass1() == None
  True
  >>> set((MyClass1(), MyClass2(), 1, True))
  {<__main__.MyClass1 object at 0x7f8f3532a820>}
  >>>

Consult your little red book. It explains the situation very clearly.

> not even install correctly with pip install

Big surprise. :p


One does not simply pip install Communist Revolution. There are much more steps. Do you even have a manifesto?

Obviously an overlook mistake from our comrade jokteur.

https://packaging.python.org/en/latest/guides/using-manifest...


He wouldn't need to use MANIFEST.in, just fixing setup.cfg would be enough. The simplest fix would be to set py_modules = communism and remove packages from setup.cfg altogether (and then the __init__.py file in src/ could be deleted since src/ is not a package).

Author of the project here. I took very little time to write this joke, this obviously an oversight from me. I was working on my conda installation, so I didn't look further.

It is fixed now, it should be working.


Yes, it works now. Note that since you have no packages, you can omit include_package_data = True from setup.cfg, and since you no longer have the src/ directory, you can omit the options.packages.find section from setup.cfg.

pipestroika!

After reading the initial section I thought this would hook up `isinstance` or something and make all class comparisons equal. But it turned out to be equalizing the instances of the classes. But still, I enjoyed the joke.

Technically a single class is the same as classless society. The single class denotes the resolution of class conflict with the dissolution of the concepts of upper and lower classes. I think it's fine.

Yeah it doesn’t seem like people here realize the way to get to a classless society is for the proletariat to suppress the upper classes and whither the state. That’s kinda the point!

Communism is not just classless, but also stateless. Therefore, Python cannot be communist, because it is not a purely functional language.

Statelessness is communism’s endgame which it never actually archives.

I like how the author recognizes the significance of Unions to fomenting the Communist Revolution:

https://github.com/jokteur/python_communism/blob/main/src/co...




Those notes... I love it.

Equal to which class? If I have MyClass1 and MyClass2 with different body, after revolution, MyClass1 will be like MyClass2 or MyClass2 like MyClass1?

It patches each class's __eq__ and __hash__ so they return True and hash(1) respectively.

Yes, which means they also compare equal to any object whatever, and they hash equal to the integer 1 and the boolean True.

Reminds me of the silliness you'd see in "C Plus Equality"

https://github.com/TheFeministSoftwareFoundation/C-plus-Equa...


Classless in a communist country you are joking …

Read Animal farm. Told us abolishment of class is fake new and pr spin in the communist revolution. Actually the communist keep themselves as the superclass. Pig … strangely there are even upper class called human there.

—- divided line we call this —-

For IT, practically javascript is really classless as its class is just protocol in disguise…


2008: cool you can import antigravity

2022: cool you can import communism


Explains why I liked the Internet more in 2008 too.

Nothing will ever top those heady days of encyclopedia dramatica and peak 4chan, well nothing except for being a well adjusted adult who passes in mainstream society. Spasiba tovarischi!

Yes, but you could still find well adjusted adults in mainstream society once you closed 4chan. Unbelievable, underrated but true!

Hilarious

So, no rich text?

> Clone this git, pip install . where the git has been cloned, and you will have access to communism.

This cracked me up. If only it was this easy, lol!


This is the first software implementation I would describe as "not doing enough to promote resource starvation".

[flagged]


Please don't start ideological flamewars on HN. They're repetitive, and they always turn nasty.

The wretched descent into offtopic hell that we got in this case is an example of what we're trying to avoid.

https://news.ycombinator.com/newsguidelines.html


I guess `import fascism` would be still fine

I did find this funny, and then I thought "Would I still find this funny if it was `import capitalism`?

Be careful with fundamental framework imports, some of them may fetch `armed_conflict` as a dependency. It is known for numerous undefined behaviors, which may corrupt your logic (fragile base class problem) and make it non-functional.

[flagged]


We are so lucky that capitalism causes no distruction.

The idea that constant growth is possible is also not insane at all ;)


No one asked to make a false dichotomy to how awful capitalism is, yet that's the only defense you could muster.

I just wish we had some good alternatives.

lol!

Why has the truth about communism been censored in a thread about a communism-critical, satirical repo. Discussion is allowed, as long as the ugly parts aren't mentioned.

I don't see a single flagged comment, what are you on about?

What do you want to tell us about communism which we haven't yet heard?


Hilarious. Now do one about the Holocaust.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: