News for hackers. Stuff that matters.
Re:What's worked in Computer Science: 1999 vs. 2015 (2015) by tubthumper8 on Friday March 15, 2024 @04:17PM (#39720242)
Definitely agree that mainstream languages are adopting functional features, but records aren't a functional feature.

Records are basic data modeling and something that has been around since the beginning of programming languages, whether procedural or functional. It's one of the bare minimums of having a type system, and Java didn't have this due to the misguided belief that "everything is an object". I think records being added is more of a symptom of that belief weakening.

There are functional features that have made it over to Java which are the things related to functions, i.e. lambdas and such which are a welcome addition.

Re:What's worked in Computer Science: 1999 vs. 2015 (2015) by gardenhedge on Friday March 15, 2024 @05:25PM (#39720886)
Java records are object-oriented construct
Re:What's worked in Computer Science: 1999 vs. 2015 (2015) by tubthumper8 on Saturday March 16, 2024 @01:18AM (#39723570)
Maybe. It depends what the definition of "object-oriented" is, which depends what the definition of "object" is. Neither of which has any semblance of agreement among programmers.

Many people would define an object as something that has externally visible behavior and internally hidden _data_. Objects could never be compared to each other for equality, because one could not access the internal data, only its public behavior. However, Java records can be compared for equality which objects would not.

Java records also cannot be extended from. Inheritance is the only uniquely OOP feature, which doesn't apply here either.

So I'm not sure that Java records are an object-oriented construct. First, the precise definition of OO should be established, and then we'll see

Re:What's worked in Computer Science: 1999 vs. 2015 (2015) by ildjarn on Saturday March 16, 2024 @04:21AM (#39724204)
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.

Re:What's worked in Computer Science: 1999 vs. 2015 (2015) by gardenhedge on Saturday March 16, 2024 @01:47PM (#39727908)
I 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.
Re:What's worked in Computer Science: 1999 vs. 2015 (2015) by ildjarn on Saturday March 16, 2024 @04:19PM (#39729144)
Very 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.
Re:What's worked in Computer Science: 1999 vs. 2015 (2015) by tubthumper8 on Saturday March 16, 2024 @05:56PM (#39729840)
Yeah 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?

Re:What's worked in Computer Science: 1999 vs. 2015 (2015) by tubthumper8 on Saturday March 16, 2024 @06:02PM (#39729875)
> 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.

Re:What's worked in Computer Science: 1999 vs. 2015 (2015) by trenchgun on Monday March 18, 2024 @03:38AM (#39741263)
Records 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

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

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...

One sentence summary there is: "Objects — the bundling of data with operations over them — are a generalization of closures."