Live data from Hacker News

Generalizing Support for Functional OOP in R

blog.r-project.org

21–30 of 53 posts

Re: Generalizing Support for Functional OOP in R

#21

To be honest, OOP never really seemed like a good fit for R. Functional programming is a much more natural fit, given that both it and R come from a mathematical point of view. R is a great language for the mathematical/statistical stuff it was invented to do, but I don't think it will ever be a general-purpose language, and it probably would become worse at its core purpose if it tried to. More work on being easily…

Functional programming is not orthogonal to object oriented programming, they are paradigms that can be used together and the popular object system developed in Java is not close to the only way to do OOP. R, like Common Lisp, uses an OOP system based on generic functions (well, one of many OOP systems in R, but that's a different topic), where the function handles dispatching to match the object. Effectively instead…

> Effectively instead of object.method() you have method(object)

This reflects a very deep misunderstanding of the distinctive characteristics of each paradigm. It's so far off that it's "not even wrong".

Functional programming is much more about things like purity and referential transparency, about composing functions and/or combinators, about a particular way of managing or modelling effects, about a way of thinking, about using certain kinds of data structures and algorithms.

It's not a syntactical difference.

Re: Generalizing Support for Functional OOP in R

#22
post #21

Earlier quoted context omitted.

Functional programming is not orthogonal to object oriented programming, they are paradigms that can be used together and the popular object system developed in Java is not close to the only way to do OOP. R, like Common Lisp, uses an OOP system based on generic functions (well, one of many OOP systems in R, but that's a different topic), where the function handles dispatching to match the object. Effectively instead…

> Effectively instead of object.method() you have method(object) This reflects a very deep misunderstanding of the distinctive characteristics of each paradigm. It's so far off that it's "not even wrong". Functional programming is much more about things like purity and referential transparency, about composing functions and/or combinators, about a particular way of managing or modelling effects, about a way of thinki…

>> Effectively instead of object.method() you have method(object)

> This reflects a very deep misunderstanding of the distinctive characteristics of each paradigm.

I think the parent made a hasty reading of the GP comment. The GP shows an awareness of multiple OO systems in R.

I believe the GP is attempting to explain to a Java programmer how R could be considered object-oriented even though `plot(item)` does not "look like" what you would see in an object oriented system.

Which is to say: there is an generic function dispatch based on the type of the first argument to the function. This can be _used_ to write in an OO style.

Re: Generalizing Support for Functional OOP in R

#23
post #17
post #7

Earlier quoted context omitted.

Some detail about that phrase https://www.catalyst.org/2021/03/22/racism-misogyny-asian-am...

I can honestly say that I had never heard that phrase used before now, but I do know I felt icky when I read it in the comment before I even clicked on your link. Definitely glad to see it is being called out, terms like this absolutely need to be removed from modern discourse.

[deleted]

Re: Generalizing Support for Functional OOP in R

#25
post #4

Earlier quoted context omitted.

OOP has been a critical part of real-life R for a long time, especially in complex implementations of classes of kernels, algorithms, and so on with S4, and more general-purpose with R6. Without these frameworks it would be difficult to implement them. Personally I find it more expressive for general-purpose computation than Python. The "fs" library is much better at working with files and paths than Python "os" and…

> I suspect lazy evaluation is a part of this. I had no idea R was lazy. Makes me wanna learn it now.

R is not lazy. It has non-standard evaluation mechanisms (formulas, promises, quosures...) that enable to you to write domain-specific languages that "do what the user meant".

If your code (or the code of the libraries you're using) doesn't use any non-standard evaluation tools, evaluation will be eager and work like any other ALGOL language.

It is possible to make some objects behave in a lazy way, but this is also true of many other languages.

Re: Generalizing Support for Functional OOP in R

#26
post #4

To be honest, OOP never really seemed like a good fit for R. Functional programming is a much more natural fit, given that both it and R come from a mathematical point of view. R is a great language for the mathematical/statistical stuff it was invented to do, but I don't think it will ever be a general-purpose language, and it probably would become worse at its core purpose if it tried to. More work on being easily…

OOP has been a critical part of real-life R for a long time, especially in complex implementations of classes of kernels, algorithms, and so on with S4, and more general-purpose with R6. Without these frameworks it would be difficult to implement them. Personally I find it more expressive for general-purpose computation than Python. The "fs" library is much better at working with files and paths than Python "os" and…

Maybe too expressive and too flexible? Different R programs can have wildly different dialects, making it difficult for two R programmers to even understand each other.

I’ve seen comics depicting the learning curve for R as having local minima beyond which there are further peaks and troughs of knowledge. A beginner might learn enough to get by, but find the code of someone on the other side of one of those peaks to be a foreign language.

Having your coders not understand each other is problematic in a production environment.

Re: Generalizing Support for Functional OOP in R

#28
post #26
post #4

Earlier quoted context omitted.

OOP has been a critical part of real-life R for a long time, especially in complex implementations of classes of kernels, algorithms, and so on with S4, and more general-purpose with R6. Without these frameworks it would be difficult to implement them. Personally I find it more expressive for general-purpose computation than Python. The "fs" library is much better at working with files and paths than Python "os" and…

Maybe too expressive and too flexible? Different R programs can have wildly different dialects, making it difficult for two R programmers to even understand each other. I’ve seen comics depicting the learning curve for R as having local minima beyond which there are further peaks and troughs of knowledge. A beginner might learn enough to get by, but find the code of someone on the other side of one of those peaks to…

This is fair. For what it's worth, Python is tending toward this and I think is introducing newer syntax at a faster rate with things such as structural pattern matching and typing, which I have had difficulty explaining to people who don't keep up with each new release.

Re: Generalizing Support for Functional OOP in R

#29

Earlier quoted context omitted.

> I suspect lazy evaluation is a part of this. I had no idea R was lazy. Makes me wanna learn it now.

R is not lazy. It has non-standard evaluation mechanisms (formulas, promises, quosures...) that enable to you to write domain-specific languages that "do what the user meant". If your code (or the code of the libraries you're using) doesn't use any non-standard evaluation tools, evaluation will be eager and work like any other ALGOL language. It is possible to make some objects behave in a lazy way, but this is also…

Thank you for the correction. Is it possible to use NSE in say Python or JavaScript?

Re: Generalizing Support for Functional OOP in R

#30
post #7
post #6

Earlier quoted context omitted.

OOP as used in R is very much a function of API design and not a function of routine R usage for data analysis. To many users of R they are not even aware that they are using OOP at all, especially for the S3 style of objects. When you have an object, like `model summary()` ends up being very natural, and when you fit in the tidyverse operators many very complex workflows end up being very easy to digest. But when yo…

Some detail about that phrase https://www.catalyst.org/2021/03/22/racism-misogyny-asian-am...

Pretty sure the phrase GP was looking for was "pull back the curtain", which likely originated with The Wizard of Oz.
Post reply on HN