像R / SAS这样的统计编程语言是否被认为是功能性或程序性的 [英] Are statistical programming languages like R/SAS considered functional or procedural

查看:171
本文介绍了像R / SAS这样的统计编程语言是否被认为是功能性或程序性的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读 this



因此,我想,也许我熟悉的一种语言可以用作功能和程序编程之间的区别一个例子。



因此,我的问题是:R / SAS语言是否被认为是程序性的或功能性的?

解决方案

R主要是一种功能性编程语言。它有一些例外情况,即通过副作用来完成,所以它不像Haskell那样完全有效。尽管如此,如果你不愿意适应你的编程风格来使用函数,那么在编写高效的R代码时会有相当多的困难。 (我写这个答案的唯一原因是,调用R一个面向对象的语言会误导那些期望能够以与Java相同的方式将函数消息发送到数据对象的人。 R使用对象的类作为泛型函数的调度选择机制,但这与完整的OO语言不同。)



R有三个,四个,或五个主要的对象类,这取决于你如何看待它们和相关的函数类型。虽然可能派发到多个参数签名的S4类在BioConductor世界中被广泛使用,但是仅派发它们的第一个参数类的原始S3函数可能仍然是最常用的。参考分类或R5或原始分类的对象最类似于真正的面向对象编程数据类型。我在最后一句话中有点含糊,因为我缺乏太多的经验。

SAS主要是一种程序语言。您可以定义函数,但它不是大多数人与SAS及其数据集进行交互的方式,至少在第一时间。至少在15年前我使用它时,它并没有真正的对象模型。我认为它的主要优势是对报告撰写的出色支持。

(数据操作在R中很难的评论意味着缺乏经验。我在R中进行数据操作所需的代码量比我的SAS同事使用的代码少很多,如果你开始使用SAS进行编程,那么转换将会很困难,但是我们这些改变了的人一般都会遇到R. )

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?

解决方案

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

这篇关于像R / SAS这样的统计编程语言是否被认为是功能性或程序性的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆