r/ProgrammerHumor • • May 16 '21

StackOverflow in a nutshell.

Post image
14.8k Upvotes

675 comments sorted by

View all comments

Show parent comments

218

u/[deleted] May 16 '21

has anyone?

43

u/individual_throwaway May 16 '21

I am almost certain that in any given field, there is a subject that nobody really understands.

In physics, it's quantum mechanics. In programming, inheritance might be a hot contender, together with regular expressions.

20

u/superluminary May 16 '21

It’s a funny joke. But there are some very real difficulties with classical inheritance, the main one being “what is a class”? If a class if an object, then it must necessarily have a class of it’s own, so what’s the class of Class? Logically, the class of Class is Class, so you have a circular inheritance loop at the top of your hierarchy.

Alternately you can say that a class is not an object, it is syntax. This creates a whole other set of problems. Where do you put your static methods? How do you manipulate classes? You need a whole introspection API.

JavaScript sidesteps all these issues with prototypical inheritance, which is way simpler.

1

u/gilbes May 17 '21

A class is not an object.

Classes are used to generate types. In a reflective environment, there may be an API to get information about the class used to generate types, but that API will give you a type that represents the class, not the class itself.

Where do you put your static methods?

Maybe you don't understand the point of classes. It is a way of organizing code within a language. A class is a unit of code organization. Your static methods are put within that class unit to organize it.

How do you manipulate classes?

By editing the code.

→ More replies (2)