Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[오혜성] 챕터 4: 액션에서 계산 빼내기 #19

Merged
merged 1 commit into from
May 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions 챕터_4/오혜성.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 액션에서 계산 빼내기
* 액션은 코드 전체로 퍼지기 쉽다
+ 어떤 함수 안에 액션이 하나만 있어도 그 함수 전체가 액션이 됨

## 함수의 입력과 출력

* 입력과 출력은 명시적이거나 암묵적일 수 있다
+ 인자와 리턴값은 명시적이고
+ 인자 외의 입력과 리턴값 외의 다른 출력은 암묵적이다

* 암묵적 입력과 출력이 있으면 액션이 된다

* 테스트와 재사용성은 입출력과 관련있다


## 액션에서 계산 빼내기

* 기존 함수에서 동작을 뺴내어 서브루틴을 추출해 계산으로 만들 수 있음
+ 코드가 더 많아진 거 같은데요?
- 일반적으로 더 적은 코드가 좋지만, 서브루틴을 추출해 테스트하기 쉽고 재사용하기 좋은 코드가 될 수 있음.

* 다른 곳에서 쓰기 위해서가 아니더라도 계산으로 분리하면 좋나?
+ 좋다. 작은 것은 테스트하기 쉽고, 재사용하기 쉽고, 이해하기 쉽기 때문

## 계산 추출을 단계별로 알아보기

1. 계산 코드를 찾아 뺀다
2. 새 함수에 암묵적 입력과 출력을 찾는다
3. 암묵적 입력은 인자로, 암묵적 출력은 리턴값으로 바꾼다

> 현실 세계에서 적용하는 방법은?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리액트 기준 컴포넌트 레벨로 생각해보는것도 괜찮을 것 같아요!

Loading