函数式编程和面向对象式编程_比较函数式编程,命令式编程和面向对象的编程

本文探讨了函数式编程(FP)、命令式编程(IP)和面向对象编程(OOP)的区别和优缺点。FP强调无状态和不可变数据,其优势包括无错误代码、高效并行编程和更好的可读性,但可能需要更多内存。OOP基于对象,支持封装、继承和多态,但过度依赖继承可能导致问题。文章提供了何时选择FP或OOP的指导。
摘要由CSDN通过智能技术生成

函数式编程和面向对象式编程

As Oracle Corporation has introduced some Functional constructs in Java SE 8, now-a-days most of the Interviewers are interested to ask some questions about Functional Programming.

随着Oracle Corporation在Java SE 8中引入了一些Functional构造,如今,大多数采访者都想问一些有关Functional Programming的问题。

As a Java/Groovy/Scala Developer or any Functional Programming Developer, we should learn the following questions and answers to clear interviews:

作为Java / Groovy / Scala开发人员或任何函数编程开发人员,我们应该学习以下问题和答案以进行清晰的访谈:

  1. What is Functional Programming?

    什么是函数式编程?
  2. What are the “Pros & Cons” of Functional Programming?

    什么是函数式编程的“利弊”?
  3. What are the differences between Functional Programming and Imperative Programming?

    函数式编程和命令式编程之间有什么区别?
  4. What are the differences between Functional Programming and Object Oriented Programming?

    函数式编程和面向对象的编程之间有什么区别?
  5. What are the differences between Functional Programming, Imperative Programming(IP) and Object Oriented Programming?

    函数式编程,命令式编程(IP)和面向对象的编程之间有什么区别?
  6. What are the major advantages of Functional Programming over Imperative Programming or Object Oriented Programming?

    与命令式编程或面向对象的编程相比,函数式编程的主要优势是什么?
  7. When to use Functional Programming?

    何时使用函数式编程?
  8. When to use Object Oriented Programming?

    何时使用面向对象编程?
  9. What are the drawbacks of OOP?

    OOP的缺点是什么?
  10. What are the drawbacks of OOP-Inheritance?

    OOP继承的缺点是什么?
  11. … And More

    … 和更多

In this post, we are going to discuss about the following three popular Programming paradigms one by one and also answer above questions:

在本文中,我们将一个接一个地讨论以下三种流行的编程范例,并回答以上问题:

  1. Functional Programming (FP)

    函数式编程(FP)
  2. Imperative Programming (IP)

    命令式编程(IP)
  3. Object Oriented Programming (OOP)

    面向对象编程(OOP)

什么是函数式编程? (What is Functional Programming?)

In simple words, Functional Programming (FP) is one of the popular Programming paradigms, which does computation like Mathematical Functions without Changing State and Mutating Data.

简而言之, 函数式编程(FP)是一种流行的编程范式,它可以像数学函数一样进行计算,而无需更改状态更改 数据

In Functional Programming, Functions are first class candidates. We write programs by defining a set of Functions and Immutable Data.

在函数式编程中,函数是一等候选。 我们通过定义一组函数和不可变数据来编写程序。

Examples of FP Languages:-
Scala, Haskell, Earlang etc are popular FP Languages. Java SE 8 also have some Functional Constructs (Please refer Java 8 posts for more details)

FP语言示例:-
Scala,Haskell,Earlang等是流行的FP语言。 Java SE 8也具有一些功能构造(有关更多详细信息,请参阅Java 8帖子)

FP的特点是什么? (What are the Characteristics of FP?)

Functional Programming Languages like Scala have the following Characteristics

像Scala这样的函数式编程语言具有以下特征

  1. State does not exist.

    状态不存在。
  2. FP Programs does not contain state. That means all Data is Immutable Data and Functions cannot change state.

    FP程序不包含状态。 这意味着所有数据都是不可变数据,功能不能更改状态。

  3. Low importance of Order of Execution

    执行命令的重要性低
  4. In FP Languages, we write programs with a set of Independent Functions. Functions contain a set of statements.
    In FP, the order of execution of those Functions does not have much importance because they do not have state and all Functions work independently. Even if we change the order of execution still they produce the same results.

    在FP语言中,我们编写具有一组独立功能的程序。 函数包含一组语句。
    在FP中,这些功能的执行顺序并不重要,因为它们没有状态并且所有功能都独立工作。 即使我们更改执行顺序,它们仍然会产生相同的结果。

  5. Stateless Programming Model

    无状态编程模型
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值