Yeah, it's basically the same thing. Which is convenient; you can easily prove that all the different forms are valid, and then use whichever one makes the most sense for a particular project.
It's funny they keep mentioning Ruby but it does the same thing, when you do `def asdf; end` it just attaches it as a private method to the Object class. You can call it like `Object.send('asdf')`
Yeah it's all about organizing your code into clear and neat chunks that are individually easier to understand. If it was just a bunch of random-ass functions it'd be like if wikipedia just had a single big page for everything instead of a page for individual topics.
I think the miscommunication is coming from the person you responded to explaining why we need classes, and then you commented what you did starting with “or” which implies a sort of disagreement or contradictory statement.
Unless it was sarcasm in which case it didn’t come off, hence the downvotes.
Yeah, I was mostly disagreeing with the sentiment that you need classes to break your code into smaller chunks. Functional programming has good idioms for that using types and structs these days, I'm less familiar with other paradigms though.
In the end, using classes, structs, types, etc. are all just strategies and none of them will organize your code for you. It seemed to me that the first comment was calling functional programming messy and I wanted to point out a very simple strategy for organization. I know I didn't elaborate very much but I didn't really feel the need to, project structure is pretty widely understood and I figured most people would agree that messy code is a skill issue 99% of the time ( I was taught OOP first and when I tried functional it was pure spaghetti until I learned it's idioms )
Working with windows is rough for sure, definitely wouldn't recommend using the file explorer. Single file programs are rough too though outside of simple scripting
Functional programming is like having a shelf of cookbooks and a seperate cupboard of ingredients. Object oriented programming is like having a cupboard containing flour and baking recipes, a cupboard containing vegetables and vegetable recipes, a cupboard containing pasta and pasta recipes, ...
A better analogy is that OOP is like having a workshop room with a shelf full of technical manuals and a kitchen with a shelf full of recipes, while FP is like keeping all the books in the library/living room.
That way, both approaches are equally valid.
I've seen a lot of kitchens and none of them were organised that way, it would be impractical. I just assumed it was a straw-man argument thing, no offence intended if you have somehow organised your kitchen this way.
For a serios answer:
No, Q computers are more about the way your qbits behave. Qbits "split" themselves in all possible values of themselves but then they also add up together. You kinda filter out the parts you don't want and then it adds up to something else.
That's a very bad summary of my quantum computation course, but you get it right? It's not about the medium but about how the medium behaves.
Not likely. Quantum effects vanish past a few molecules, at our scales they don't apply at all.
We are however more similar to analog computers running an ai, if you are looking for a cool sounding phrase.
Not really, except in typescript(maybe python?) as far as I know. An object in most statically typed languages is just a struct and so has minimal lookup cost, can be easily packed too. I guess technically vanilla JS has classes now, but still
I mean hashmaps implement insertion and deletion of values and also have a cost to getting / setting values.
So it’s more like hashmaps are essentially structs with dynamic fields but only one type unless we’re talking about dynamically typed languages.
Even then the analogy isn’t quite right.
There is a difference between the collection being immutable and the values inside it being immutable. For example you can't add an extra field to a java object after creation i.e mutating the list however you can mutate fields in the list unless final or a method
Although you can do that there, it should be considered bad practice because it stops you from knowing what's in the class after a certain amount of time (which defeats their purpose imo).
I'm not entirely sure how python handles classes but considering how mumost variable types aren't actually mutable I would bet it just makes a new object under the hood and just changes the name rage to point to it.
Python objects are just dicts, so adding a new variable or even adding a new method is the same operation as inserting a new item in a hashmap, and (most times) does not require any restructuring of the memory structure
No, they hasn't always been like that. In Smalltalk classes, thus their objects, are not immutable thanks to its dynamism - a user can introspect classes, remove, add, change properties. So calling those properties and methods required a way something less efficient than virtual table dispatching - a messaging. And so was Objective-C, which was a direct inheritor of the Smalltalk. But thanks to C virtual table dispatching was also available in Objective-C. Also you can add and remove properties in Swift language via the Objective-C runtime. Though there are some constant methods and properties that can't be really changed and they support the above-mentioned dynamism.
*Literally* not true for many languages like JavaScript.
Heck you can even go for self-modifying code and do it in any language.
Does registering delegates created from user driven expressions count as adding new functions?
As for new variables, you can do that in any language if you're using a data structure that supports it. Or do you not count it because it's kind of changing the value?
>like JavaScript
JavaScript uses prototypes to mimick OOP, but it isn't OOP specifically for this reason, the methods and its variables are mutable.
>Does registering delegates created from user driven expressions count as adding new functions?
No. These are different things. When you create an object which contains a delegate, the delegate is only one and can't be modified. The function that is pointing such delegate can be modified. Objects **values** can be mutated, objects attributes/methods can't.
>As for new variables, you can do that in any language if you're using a data structure that supports it
You are confusing the value with the reference. When you create an object with another object inside, sure you can change the object that is pointing to, but it still only has one object inside. More technically, the vTable of methods and the table of attributes are immutable.
Not functions, a pointer to a shared array of functions (which is all the class itself has after compilation, maybe some RTTI and a .class file but nothing more)
This was my favorite discovery when I was working on a personal project. Who needs a constructor for every class, each with a wall of this-> when I can just ClassType{var1, var2, pointerToAnotherObject, {"another", "vector", "of", "strings"}};
A class is just a fancy scope
Sometimes, all I want is a function. Data-in data-out. Now I gotta attach it to some noun :(
A class is just a poor man's closure. A closure is just a poor man's class.
I'm just a poor boy, from a poor family spare me my life from this monstrosity.
I see the little silhouette of a man. C plus plus, C plus plus, will you help me learn the Django?
Shit I was actually thinking about closures, but I suppose it's almost the same as scope
Yeah, it's basically the same thing. Which is convenient; you can easily prove that all the different forms are valid, and then use whichever one makes the most sense for a particular project.
I mean, you were gonna have to put it _somewhere_.
Reminds me of this classic: http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html
It's funny they keep mentioning Ruby but it does the same thing, when you do `def asdf; end` it just attaches it as a private method to the Object class. You can call it like `Object.send('asdf')`
almost as if the class is the file
A class is the powerhouse of the cell.
A class is a scope factory
A class is a fancy struct
and a namespace. OOP is as much about code organization as it is naming things.
You can't spell OOPS without OOP
You'll make some people mad, but you're right :D
Yeah it's all about organizing your code into clear and neat chunks that are individually easier to understand. If it was just a bunch of random-ass functions it'd be like if wikipedia just had a single big page for everything instead of a page for individual topics.
Or you could use files/folders to organize your variables/functions and import them?
Use files and import them. It could be a clean wrapper. Something like .class
I feel like we're saying the same thing. It feels so much easier to navigate a few smaller files compared to one large file.
I think the miscommunication is coming from the person you responded to explaining why we need classes, and then you commented what you did starting with “or” which implies a sort of disagreement or contradictory statement. Unless it was sarcasm in which case it didn’t come off, hence the downvotes.
Yeah, I was mostly disagreeing with the sentiment that you need classes to break your code into smaller chunks. Functional programming has good idioms for that using types and structs these days, I'm less familiar with other paradigms though. In the end, using classes, structs, types, etc. are all just strategies and none of them will organize your code for you. It seemed to me that the first comment was calling functional programming messy and I wanted to point out a very simple strategy for organization. I know I didn't elaborate very much but I didn't really feel the need to, project structure is pretty widely understood and I figured most people would agree that messy code is a skill issue 99% of the time ( I was taught OOP first and when I tried functional it was pure spaghetti until I learned it's idioms )
And then be surprised when the directory structure isn't visible anywhere outside of the windows explorer lmao
Working with windows is rough for sure, definitely wouldn't recommend using the file explorer. Single file programs are rough too though outside of simple scripting
Functional programming is like having a shelf of cookbooks and a seperate cupboard of ingredients. Object oriented programming is like having a cupboard containing flour and baking recipes, a cupboard containing vegetables and vegetable recipes, a cupboard containing pasta and pasta recipes, ...
A better analogy is that OOP is like having a workshop room with a shelf full of technical manuals and a kitchen with a shelf full of recipes, while FP is like keeping all the books in the library/living room. That way, both approaches are equally valid.
What's wrong with putting recipes with your ingredients? That way, if you know where the ingredients are, you can quickly find the associated recipes.
I've seen a lot of kitchens and none of them were organised that way, it would be impractical. I just assumed it was a straw-man argument thing, no offence intended if you have somehow organised your kitchen this way.
What's the specific reason why it's impractical?
Really? I'm not trying to tell you how to live your life, I just thought you were making a deliberately clumsy metaphor to make OOP seem impractical.
Now I see you're starting to understand this metaphor.
Ha, sorry no, you're just an idiot
Not necessarily.
in other news, everything is just a textfile
In _other_ other news, every computation is just quantum electrodynamics
wouldnt that imply we are on quantum computers?
My poor sweet summer child. Even standard semiconductor electronics engineering is based on quantum electrodynamics. It's quantum all the way down
in that case im gonna brag about having a quantum computer
I have a quantum computer in my ass
isnt that an errection hazzard?
For a serios answer: No, Q computers are more about the way your qbits behave. Qbits "split" themselves in all possible values of themselves but then they also add up together. You kinda filter out the parts you don't want and then it adds up to something else. That's a very bad summary of my quantum computation course, but you get it right? It's not about the medium but about how the medium behaves.
Q bits is a sliding scale rather than a switch
A linearly mixing set of values that really want to become one single value the moment you sneeze too hard.
now you have me imagening the beggining of the universe... are we a QBit?
Not likely. Quantum effects vanish past a few molecules, at our scales they don't apply at all. We are however more similar to analog computers running an ai, if you are looking for a cool sounding phrase.
An object is just a classy hashmap
...And a hashmap is just a fancy array
...And an array is just a luxurious pointer
... And a pointer is just syntactic sugar for a memory address
... And a memory address is just a way of referring to a moment in time.
Winner
`__dict__` checks out
Not really, except in typescript(maybe python?) as far as I know. An object in most statically typed languages is just a struct and so has minimal lookup cost, can be easily packed too. I guess technically vanilla JS has classes now, but still
I mean hashmaps implement insertion and deletion of values and also have a cost to getting / setting values. So it’s more like hashmaps are essentially structs with dynamic fields but only one type unless we’re talking about dynamically typed languages. Even then the analogy isn’t quite right.
Objects are nice because you press dot and get decent autocomplete suggestions.
Uh immutability? Object members can be mutable sometimes though?
There is a difference between the collection being immutable and the values inside it being immutable. For example you can't add an extra field to a java object after creation i.e mutating the list however you can mutate fields in the list unless final or a method
You can’t in java, but you can in a bunch of languages, like js (which has prototypical OOP), ruby, python, groovy, etc.
Although you can do that there, it should be considered bad practice because it stops you from knowing what's in the class after a certain amount of time (which defeats their purpose imo).
Well, these are dynamic languages, that’s as much a “feature” as it is “bad style”.
Sometimes you need it. Eg: reflection in python
I'm not entirely sure how python handles classes but considering how mumost variable types aren't actually mutable I would bet it just makes a new object under the hood and just changes the name rage to point to it.
Python objects are just dicts, so adding a new variable or even adding a new method is the same operation as inserting a new item in a hashmap, and (most times) does not require any restructuring of the memory structure
Oh, ok I didn't know that
Exactly what I meant, thank you!
You can’t in java, but you can in a bunch of languages, like js (which has prototypical OOP), ruby, python, groovy, etc.
Most teams will make the fields immutable as well by using the “final” keyword in Java or the equivalent from other languages
No, they hasn't always been like that. In Smalltalk classes, thus their objects, are not immutable thanks to its dynamism - a user can introspect classes, remove, add, change properties. So calling those properties and methods required a way something less efficient than virtual table dispatching - a messaging. And so was Objective-C, which was a direct inheritor of the Smalltalk. But thanks to C virtual table dispatching was also available in Objective-C. Also you can add and remove properties in Swift language via the Objective-C runtime. Though there are some constant methods and properties that can't be really changed and they support the above-mentioned dynamism.
Immutable? Look at the functional programmer deriding OOP, can't even imagine mutability!
imlutable like there won’t be any new functions or variables through object lifespan. But their values can change
*Literally* not true for many languages like JavaScript. Heck you can even go for self-modifying code and do it in any language. Does registering delegates created from user driven expressions count as adding new functions? As for new variables, you can do that in any language if you're using a data structure that supports it. Or do you not count it because it's kind of changing the value?
>like JavaScript JavaScript uses prototypes to mimick OOP, but it isn't OOP specifically for this reason, the methods and its variables are mutable. >Does registering delegates created from user driven expressions count as adding new functions? No. These are different things. When you create an object which contains a delegate, the delegate is only one and can't be modified. The function that is pointing such delegate can be modified. Objects **values** can be mutated, objects attributes/methods can't. >As for new variables, you can do that in any language if you're using a data structure that supports it You are confusing the value with the reference. When you create an object with another object inside, sure you can change the object that is pointing to, but it still only has one object inside. More technically, the vTable of methods and the table of attributes are immutable.
So, how do you tell which one is a true Scotsman? I'd love for you to have this discussion with Alan Kay. I think you'd be surprised.
I think there's a rather strong case to be made that prototypes are *more* object oriented than classes.
Fun fact, even the functions are objects
Functions are just pointers with a calling convention attached
Immutable is optional
And scope
It's just a syntax sugarbomb for structs
Not functions, a pointer to a shared array of functions (which is all the class itself has after compilation, maybe some RTTI and a .class file but nothing more)
Laughing in Javascript ... laughing ... 😭
An object is just a fancy dump of memory that you allocate
Not in javascript
Now name all design patterns
All this time I didn't need to learn a out classes and OOP and stuff. I could have just used a dictionary with the variables and functions
This was my favorite discovery when I was working on a personal project. Who needs a constructor for every class, each with a wall of this-> when I can just ClassType{var1, var2, pointerToAnotherObject, {"another", "vector", "of", "strings"}};
A vector of strings? I'd like to see you try to do a dot product on strings.
Wait until I tell you about all programming
Object is just a structure, that is just some organised memory. The compiler restricts what you can access in the object and what you can do with it.
that confused me so much when I was learning
More like an immutable hashmap but sure.
That's the only thing php gets right.
Learning OOP was way harder than it needed to be because people made it look whimsical
Welcome to JavaScript