我经常遇到面向对象编程和函数式编程以及命令式编程和函数式编程之间的比较。“面向对象”和“祈使”是两个不同的术语,据我理解,它们之间没有任何关系。不过,它们都与函数式编程相比较。是什么关系的面向对象和命令式编程的动机,这样的比较?
发布于 2014-01-20 23:26:10
原因很简单,主流的面向对象编程(即Java,C#)是命令式编程的一个子类别。
这是一个粗略的图表:
progamming
/ \
declarative imperative
/ \ / \
functional \ OO procedural
logic
(prolog)在声明式编程中,您可以说出要计算的内容。假设我们想要计算链接列表的长度:
在命令式编程中,基本上按照一定的顺序操作内存:
int length = 0; // put starting value in memory
while (!list.isEmpty()) {
length++; // update memory
list = list.next(); // update list pointer for next iteration
}
// result is in memory location associated with length因此,适当的比较是:
https://stackoverflow.com/questions/21245841
复制相似问题