“函数"和“函数"之间有什么区别?和“程序"? [英] What is the difference between a "function" and a "procedure"?
问题描述
一般来说,我们都听说过编程语言中的函数或过程.然而,我刚刚发现我几乎可以互换使用这些术语(这可能是非常错误的).
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).
所以,我的问题是:
它们的功能、目的和用途有何不同?
What is the difference in terms of their functionality, their purpose and use?
一个例子将不胜感激.
推荐答案
一个函数返回一个值,一个过程只执行命令.
A function returns a value and a procedure just executes commands.
name 函数来自于数学.用于根据输入计算一个值.
The name function comes from math. It is used to calculate a value based on input.
过程是一组可以按顺序执行的命令.
A procedure is a set of commands which can be executed in order.
在大多数编程语言中,甚至函数也可以有一组命令.因此区别只是返回一个值.
In most programming languages, even functions can have a set of commands. Hence the difference is only returning a value.
但是如果你想保持一个函数的简洁(只看函数式语言),你需要确保一个函数没有副作用.
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屋!