Are statistical programming languages like R/SAS considered functional or procedural [closed]
Asked Answered
L

2

16

I still don't understand the difference after reading this

So, rather than asking what is the difference between functional vs procedural programming, I thought, maybe a language that I am familiar with can serve as an example.

Hence, my questions: Are the languages R/SAS considered procedural or functional?

Latour answered 30/6, 2015 at 18:16 Comment(2)
I can give you what Hadley Wickham thinks about your question, read here.Dyeing
One could split this question into two since R and SAS are quite different, particularly when it comes to object-oriented programming.Inchoative
Q
24

R is primarily a functional programming language. It does have some exceptions where things are done via side-effects, so it's not as entirely functional as Haskell. Nonetheless, if you are not willing to adapt your programing style to use functions, you will have quite a bit of difficulty in writing efficient R code. (The only reason I'm writing this answer is that calling R an object-oriented language will be misleading to people who come to it expecting to be able to send function messages to data-objects in the same manner as they do with Java. R uses an object's class as the dispatch selection mechanism for "generic" functions, but that's not the same paradigm as full OO-languages.)

R has between three, four, or five major object classes depending on how you think about them and associated function-types. The original S3 functions which dispatch only on the class of their first arguments are probably still the most commonly used, although the S4-class which may dispatch on multiple argument signatures is widely used in the BioConductor world. Reference-classed or R5 or proto-classed objects most resemble true object-oriented programming data types. I'm being a bit vague in that last sentence, because I lack much experience with them.

SAS is primarily a procedural language. You can define functions but it's not the way most people interact with SAS and its data SETs, at least at first. At least when I used it 15 years ago, it didn't really have an object model. I would argue that its main advantage is superior support for "report writing".

(The comment that data manipulation is "hard in R" just indicates lack of experience. The amount of code I need for data manipulation in R is a lot less than the code used by my SAS colleagues. If you started programming in SAS, then the conversion will be hard, but those of us who have changed generally have stuck with R.)

Quassia answered 30/6, 2015 at 18:52 Comment(6)
Are not the macros is SAS the equivalent of functions? I am sure inventors of SAS think of it as procedural, because everything is a 'proc' :)Latour
@Latour : I did say you could define functions with SAS, although I doubt there is much in the way of a dispatch mechanism as with R. I strongly suspect it is still not the case that new SAS users are being taught to write SAS-macros.Quassia
Thanks. I read that functional languages are naturally suited for parallel processing. Is it easy to do parallel processing in R, similar to let us say (Java's executor framework)Latour
R has the parallel package, but R is not multi-threaded, so will not necessarily dispatch to multiple CPUs the way some languages do. The hurdle is often constructing your algorithms and workflow in a manner that is naturally "parallelizeable".Quassia
I have no experience with SAS at all, but is "superior support for report writing" really still true, considerung all the new tools available for R: R Markdown, Shiny, Slidify, ... ? I actually have a hard time imagining anything superior for report generation.Thoria
I grant your point. I never really liked the tablular format for reports from SAS anyway, but they were considered the norm at one time. I would, however, ask if Shiny belongs in the list of "report" facilities unless one broadedn the category to include "display mechanisms". I would have instead nominated knitr and Sweave.Quassia
S
0

I would say R is definitely procedural; Functional programming is much more than making use of functions, e.g., using some coarse modularity; indeed f.p. is committed to extreme modularity which is one of its primary strengths; look up the classic paper "Why functional programming matters" by John Hughes to find out more.

SAS seems more special purpose to me being designed to organize data into tables and do statistical reports on same. It seems to have no particular relationship to functional programming; I am still investigating its procedural capabilities (or lack thereof)

Salvation answered 26/9, 2016 at 20:13 Comment(1)
I disagree with your assessment and consider R to have a strong functional orientation. I especially disagree with your characterization of R as procedural. R evaluates expressions, not statements like a procedural language like SAS. Combine that with the functional orientation or encouragement of the language, and I would easily consider it a functional language.Wileen

© 2022 - 2025 — McMap. All rights reserved.