OOP vs FP

효딩딩·2022년 8월 24일
0

OOP 란 무엇인가?

  • Object Oriented Programming의 약자로써 class와 object에 기반한 프로그래밍 패러다임(디자인 패턴) 이다.
  • 즉, 관련된 데이터끼리 묶어서 class를 형성하고 그 안에서 object instance를 만듬으로써 프로그램을 디자인한다.

OOP의 장점

  • 코드의 재사용률을 높이고 코드를 간결하게 함으로써 유지보수가 쉽다.(DRY principle)
  • 데이터를 안전하게 보존할 수 있다.(encapsulation와 abstraction등)

Encapsulation(캡슐화): 객체의 내부 로직을 감추고 외부에는 상대적으로 안정적인 부분만을 공개함으로써 데이터를 안전하게 보존하는 기법이다. 캡슐화는 외부에 영향을 주지 않고 객체 내부의 구현을 변경할 수 있기 때문에 내부 로직에 대한 유연함을 제공한다.

대표적인 언어

  • C++, Java, Python, Javascript

FP 란 무엇인가?

  • side effect가 없는 pure function을 구현함으로써 프로그램을 디자인한다.
  • 여러개의 작은 function을 엮으며 하나의 큰 function을 구현하고 불변성을 지키게 됨.

FP 의 장점

  • 높은 수준의 추상화를 제공한다.
  • 함수 단위의 코드 재사용이 증가한다.
  • 디버깅이 쉽다.
  • 불변성을 지향하기 때문에 프로그램의 동작을 예측하기 쉬움

대표적인 언어

  • Clojure, Swift, Haskell, Scala

출처:
https://velog.io/@suyeonme/JavascriptOOP
https://seunghunchan.tistory.com/23


(영문 해석)

OOP vs Functional Programming: What’s The Difference?

  • Object-Oriented Programming (OOP) is the most common and widely used programming model. OOP accentuates using objects and classes. For the application of this model, we need to divide the software variables into so-called classes (object categories) and then build the architecture based on the predefined classes. This paradigm is characterized by a structure that resembles a tree with a rod and branches. Each class inherits properties from its “parent”. And all this together is a complex artificial system that integrates for ease of use of the coding language. OOP-oriented coding languages include Python, Paskal, JS, C ++, Java, etc.

  • Why is OOP Good?
    - OOP reproduces simple and understandable structures from complex things.
    - You can reuse OOP objects to write other programs.
    - Many libraries and frameworks speed up the development as can be easily integrated into your architecture.
    - A wide segment of OOP developers is ready to assist you in any task.

  • Functional programming is a manner of software engineering in which we try to describe the solution via a mathematical function. This concept of coding belongs to declarative ones. In the OOP, the accent is on “how do we solve this?” At the same time, the FP focuses on “what do we solve?”. Some of the popular functional languages are Haskell, Rust, Nix, Elixir.

  • What Are the Pros and Cons of FP?
    The FP functions are easy to comprehend since they do not alter in any way and depend only on the input data. What output we get from these functions is the outcome of the value they bring. Their signature can give us all the required data about them.

  • Moreover, the code of the software you are writing becomes simpler to interpret. The reason is that FP languages can perceive functions as values, or vice versa – they transmit different values to functions presented as parameters.

  • With FP, it is easy to test software and fix bugs. The functions, in this case, are simple – they take into account the argument and generate the original data. They guarantee that they will not generate redundant or secondary data that will not be easy to understand or count.

  • As for disadvantages, the introduction of pure functions can demand from the developer to get out of the box of OOP thinking and begin to work with the programming as with the mathematical case. Furthermore, if it is simple for you to introduce all the functions it will be burdensome to incorporate them into a unified software unit. As one of the examples of these difficulties, I can mention that it is rather unusual for OOP programmers to code recursively instead of using the loop method.

Source: https://www.emizentech.com/blog/oop-vs-functional-programming.html

profile
어제보다 나은 나의 코딩지식

0개의 댓글