11 ms·
OOP is about bundling state and behaviour into units that hide their internal mechanisms by some kind of interface. Records can have no state - compared to reg
by ildjarn 3y ago
OOP is about bundling state and behaviour into units that hide their internal mechanisms by some kind of interface.
Records can have no state - compared to regular classes - so they are an anti-OOP feature.
- gardenhedge 3y agoI would say OOP revolves around the concept of modeling real-world entities or concepts as objects in code. Records encapsulate data fields within an object, providing a way to model real-world entities.
- ildjarn 3y agoVery few classes model a real world entity in my experience. Maybe that was the plan but it’s just not the reality of OOP in the industry.
- tubthumper8 3y agoYeah this is why I always chuckle when people claim that OOP "models the real world". Oh, because your "FooWidgetController", "FooWidgetService", "FooWidgetRepository" are all real world things?
- tubthumper8 3y ago> I would say OOP revolves around the concept of modeling real-world entities or concepts as objects in code. This is just data modeling, has nothing to do with OOP.
- trenchgun 3y agoRecords existed before and influenced OOP, and they exist outside of OOP today, in imperative and pure functional languages: https://en.wikipedia.org/wiki/Record_%28computer_science%29 https://en.wikipedia.org/wiki/Record_%28computer_science%29 Summary by Wikipedia is pretty good: >Object-oriented programming (OOP) is a programming paradigm based on the concept of objects,[1] which can contain data and code: data in the form of fields (often known as attributes or properties), and code in the form of procedures (often known as methods). In OOP, computer programs are designed by making them out of objects that interact with one another. But also, from same wikipedia page: >Attempts to find a consensus definition or theory behind objects have not proven very successful (however, see Abadi & Cardelli, A Theory of Objects[68] for formal definitions of many OOP concepts and constructs), and often diverge widely. For example, some definitions focus on mental activities, and some on program structuring. https://en.wikipedia.org/wiki/Object-oriented_programming https://en.wikipedia.org/wiki/Object-oriented_programming But I also recommend reading the chapter on objects from "Programming Languages: Application and Interpretation" by Shriram Krishnamurthi. https://www.plai.org/3/2/PLAI%20Version%203.2.2%20electronic.pdf https://www.plai.org/3/2/PLAI%20Version%203.2.2%20electronic... One sentence summary there is: "Objects — the bundling of data with operations over them — are a generalization of closures."