# 깔끔한 코드를 원하면 "Rule of Six"만 기억하세요

> Clean Markdown view of GeekNews topic #7493. Use the original source for factual precision when an external source URL is present.

## Metadata

- GeekNews HTML: [https://news.hada.io/topic?id=7493](https://news.hada.io/topic?id=7493)
- GeekNews Markdown: [https://news.hada.io/topic/7493.md](https://news.hada.io/topic/7493.md)
- Type: news
- Author: [xguru](https://news.hada.io/@xguru)
- Published: 2022-09-28T10:21:01+09:00
- Updated: 2022-09-28T10:21:01+09:00
- Original source: [davidamos.dev](https://davidamos.dev/the-rule-of-six/)
- Points: 54
- Comments: 5

## Topic Body

- 읽기 쉽고 이해하기 쉬운 코드는 한줄 한줄이 짧아야 함   
- 인간의 뇌는 장기기억(LTM)/단기기억(STM)/작업기억(WM) 세 기능이 같이 동작   
- 단기기억과 작업기억 공간은 매우 작아서 한번에 4~6개만 저장 가능   
- 즉 코드 한줄이 6+개 이상의 정보를 가지고 있다면, 간소화 해야한다는 것이 "Rule of Six"  
- 코드가 복잡하면 분할 - SIMPLE : Split Into MultiPle LinEs   
  > `map(lambda x: x.split('=')[1], s.split('?')[1].split('&')[-3:])`  
을 분할해 보면   
`query_params = s.split('?')[1].split('&')[-3:]`  
`map(lambda x: x.split('=')[1], query_params)`  
아직도 6개가 넘으니 다시 분할해 보면   
  > `url_query_string = s.split('?')[1]`  
`query_params = url_query_string.split('&')[-3:]`  
`map(lambda x: x.split('=')[1], query_params)`  
- MORF(Move Out and Rewrite as a Function)전략을 이용하면   
  > `def query_params(url):`  
  `ㅤㅤquery_string = url.split('?')[1]`  
`ㅤㅤreturn query_string.split('&')[-3:]`    
`map(lambda x: x.split('=')[1], query_params(s))`

## Comments



### Comment 12536

- Author: studroid
- Created: 2022-09-28T12:20:13+09:00
- Points: 1

오 예시가 너무 훌륭하네요 ㅎㅎ

### Comment 12530

- Author: jujumilk3
- Created: 2022-09-28T10:40:05+09:00
- Points: 2

본능적으로 한줄코딩을 싫어했는데 제 뇌의 비명이었군여

### Comment 12529

- Author: kunggom
- Created: 2022-09-28T10:33:42+09:00
- Points: 5

링크된 글 본문 마지막에 소개된 책은 국내에 [프로그래머의 뇌: 훌륭한 프로그래머가 알아야 할 인지과학의 모든 것](http://www.yes24.com/Product/Goods/108434479)이라는 이름으로 번역 출간되었습니다. 본문에 소개된 내용이 좀 더 자세히 나와 있지요.

### Comment 12541

- Author: forteleaf
- Created: 2022-09-28T22:14:08+09:00
- Points: 1
- Parent comment: 12529
- Depth: 1

저도 읽어봤는데, 위에 내용이 나와있었네요.

### Comment 12538

- Author: excovert
- Created: 2022-09-28T15:29:25+09:00
- Points: 1
- Parent comment: 12529
- Depth: 1

한번 읽어봐야겠네요! 감사합니다~
