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

不羁岁月 提交于 2019-12-03 06:21:09

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

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!