“功能”与“功能”之间的区别是什么?和“程序”? [英] What is the difference between a "function" and a "procedure"?

查看:175
本文介绍了“功能”与“功能”之间的区别是什么?和“程序”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般来说,我们都听说过编程语言中的函数过程。然而,我发现我几乎可以互换地使用这些术语(这可能是非常错误的)。

所以,我的问题是:


它们在功能,目的和用途方面有什么不同?



<

解决方案

一个函数返回一个值,一个过程只是执行命令。 b
$ b

名称函数来自数学。它用于根据输入计算一个值。

一个过程是一组可以按顺序执行的命令。



在大多数编程语言中,偶函数可以有一组命令。因此,差异仅在于返回值部分。



但是如果你想保持一个函数的干净,(只要看看函数式语言),就需要确保一个函数没有副作用。 >

Generally speaking, we all hear about the functions or procedures in programming languages. However, I just found out that I use these terms almost interchangeably (which is probably very wrong).

So, my question is:

What is the difference in terms of their functionality, their purpose and use?

An example would be appreciated.

解决方案

A function returns a value and a procedure just executes commands.

The name function comes from math. It is used to calculate a value based on input.

A procedure is a set of command which can be executed in order.

In most programming languages, even functions can have a set of commands. Hence the difference is only in the returning a value part.

But if you like to keep a function clean, (just look at functional languages), you need to make sure a function does not have a side effect.

这篇关于“功能”与“功能”之间的区别是什么?和“程序”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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