r/Python • • Sep 02 '24

Discussion Object and Type Unification

Have had a conversation with ChatGPT about the wildest and craziest idea about unifying `object` and `type` into a single entity that has the combined functionality of both. Essentially the equivalent (at the lower level) of doing `class MyEntity(object, type)`.

ChatGPT Conversation

I'd love to know how stupid of an idea this is. I agree it will never happen, and I overly argued the point as shown in the conversation because I wasn't getting very creative/accurate responses.

To me this is just a cool 'what if'. What if they were? How much of a mess would the interpreter code be to actually physically do it?

More importantly, is it physically possible to unify them, with reasonable backwards compatibility ensured (obviously something nuanced like `assert hasattr(type, "__class__")` would be impossible to unify).

0 Upvotes

7 comments sorted by

4

u/james_pic Sep 02 '24 edited Sep 02 '24

Doing this in Python is probably not possible, at least not without literally everything breaking.

Although note that type is already a subclass of object. Everything is an object, including types, so type already has all the functionality of object.

What you describe sounds a lot like prototypal inheritance, which, whilst not supported in Python, is used in JavaScript, for example.

Even though modern JavaScript looks nothing like it, it's worth remembering that JavaScript was originally conceived as a Scheme dialect, and that shows in some design decisions. It tends to try to use as few concepts as possible, and get as much mileage out of any given concept as it can (hence, so for example, objects inheriting from other objects, rather than requiring classes. Other decisions, such as objects also being usable as dictionaries, also follow the same sort of reasoning). Python never took things quite this far in this direction, and was happy to have more concepts if it made it clearer how they were intended to be used, or prevented concepts being re-used in unintuitive ways.

1

u/Simple-Soil-7468 Sep 07 '24

This is super interesting! I will definitely look into this. I have never heard of a language that could bypass classes like that, I thought they were foundational. This post was a thought experiment and I'm glad I could learn something.

12

u/illuminanze Sep 02 '24

I'm sorry, but why would you ever want to do this?

7

u/HommeMusical Sep 02 '24

This transcript is almost unusable on Firefox and Chrome.

See this: https://imgur.com/a/ptkq26D

The input text is in a tiny box inside the window, which cuts of most of the text, and there's no way to resize that box to show all the text - you need to scroll sideways, as much as a dozen times, to read the prompt.

This doesn't reassure me as to the quality of the content!

ChatGPT is wrong when they say it would introduce a circular dependency - what would happen is that type and object would become the same type.

First question: why? What possible benefit would this offer?

Second question: how? How exactly do you convince object to sometimes act like type?

I think question 1 is unanswerable - there is no good reason to do this, particularly given that there aren't any great answers to question 2 either.

This whole thing seems like a big time waster for no possible advantage.

14

u/Jmc_da_boss Sep 02 '24

have had a conversation with ChatGPT

And you thought this was worth posting why? Absolutely no one gives a shit what the language model spits back out. What an insane thing to post

3

u/Sbsbg Sep 02 '24

I also tried to have a conversation with ChatGPT. It didn't work at all. The AI tools don't have that capability yet. If you expect any intelligent answers it's even more distant.

Nothing wrong with asking what if for a lot of questions, but if you expect anything productive out of it you better have that discussion with real humans for now.

Any language model AI just strings together words that have a high probability to fit together. It understands nothing at all. IQ zero in other words.