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

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

问题描述

阅读 这个

所以,与其问函数式编程和过程式编程有什么区别,我想,也许我熟悉的一种语言可以作为一个例子.

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.

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

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

推荐答案

R 主要是一种函数式编程语言.它确实有一些例外情况是通过副作用完成的,因此它的功能不如 Haskell.尽管如此,如果您不愿意调整您的编程风格以使用函数,那么您将很难编写高效的 R 代码.(我写这个答案的唯一原因是,将 R 称为面向对象的语言会误导那些希望能够以与 Java 相同的方式向数据对象发送函数消息的人.R 使用对象的类作为通用"函数的调度选择机制,但这与完整的 OO 语言不同.)

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 有 3、4 或 5 个主要对象类,具体取决于您如何看待它们和相关的函数类型.仅在其第一个参数的类上分派的原始 S3 函数可能仍然是最常用的,尽管可以在多个参数签名上分派的 S4 类在 BioConductor 世界中被广泛使用.引用类或 R5 或原型类对象最类似于真正的面向对象编程数据类型.我对最后一句话有点含糊,因为我对他们缺乏太多经验.

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 主要是一种程序语言.您可以定义函数,但这不是大多数人与 SAS 及其数据集交互的方式,至少一开始是这样.至少 15 年前我使用它时,它并没有真正的对象模型.我认为它的主要优势是对报告写作"的出色支持.

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

(数据操作R 中很难"的评论只是表明缺乏经验.我在 R 中进行数据操作所需的代码量比我的 SAS 同事使用的代码要少得多.如果你开始在SAS,那么转换会很困难,但是我们这些已经改变的人一般都坚持使用R.)

(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天全站免登陆