“方法"与“消息"与“功能"与"???" [英] 'method' vs. 'message' vs. 'function' vs. '???'

查看:86
本文介绍了“方法"与“消息"与“功能"与"???"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近问了一个有关我所谓的方法调用"的问题.答案是消息".作为一个自学成才的业余程序员,我试图表达那些不会让我看起来像个白痴的问题,因此我意识到,我所使用的术语在很大程度上揭示了我如何学习编程.

方法/消息/等的各种术语之间是否有区别?在OO编程中?这是不同的编程语言使用不同的术语来描述相似概念的区别吗?

我似乎记得在OO之前的语言中,有时会根据是否期望返回值来区分子例程"和函数",但是即使那样,这仍是一种语言对语言的区分. ?

解决方案

我发现这是一种语言和编程范例.一种范例-OOP-指的是带有成员方法的对象,从概念上讲,它们是您如何向这些对象发送消息的方式(例如,该视图反映在UML中).

另一个范式-功能性-可能涉及对象类别,也可能不涉及对象类别,但是功能是工作的基本单元.

在结构化编程中,您具有子例程(请注意,前缀"sub"表示结构).

在命令式编程中(与结构化结构有很多重叠,但是看待事物的方式略有不同),您对世界的看法更加公式化,因此函数"表示某种操作(通常是数学上的). /p>

听起来像卢布一样,您要做的就是将语言参考所使用的​​术语用于您所使用的语言.

I recently asked a question about what I called "method calls". The answer referred to "messages". As a self-taught hobby programmer trying to phrase questions that don't make me look like an idiot, I'm realizing that the terminology that I use reveals a lot about how I learned to program.

Is there a distinction between the various terms for methods/messages/etc. in OO programming? Is this a difference that comes from different programming languages using different terminology to describe similar concepts?

I seem to remember that in pre-OO languages, a distinction would sometimes be made between "subroutines" and "functions" based on whether a return value was expected, but even then, was this a language-by-language distinction?

解决方案

I've found this to be a language and programming-paradigm thing. One paradigm — OOP — refers to objects with member methods, which conceptually are how you send messages to those objects (this view is reflected in UML, for example).

Another paradigm — functional — may or may not involve classes of objects, but functions are the atomic unit of work.

In structured programming, you had sub-routines (notice that the prefix "sub" implies structure).

In imperative programming (which overlaps with structured quite a lot, but a slightly different way of looking at things), you have a more formulaic view of the world, and so 'functions' represent some operation (often mathematical).

All you have to do to not sound like a rube is to use the terminology used by the language reference for the language you're using.

这篇关于“方法"与“消息"与“功能"与"???"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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