Community

개발자 99% 커뮤니티에서 수다 떨어요!

← Go back
3장.함수 (TIL)
#clean_code
2년 전
1,357


TIL (Today I Learned)

2022.02.22

오늘 읽은 범위

3장.함수

책에서 기억하고 싶은 내용을 써보세요.

  • The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that. (p.34)

  • It turns out to be very difficult for programmers to learn to follow this rule and write functions that stay at a single level of abstraction. But learning this trick is also very important. It is the key to keeping functions short and making sure they do "one thing." (p.37)

  • Don't be afriad to make a name long. A long descriptive name is better than a short enigmatic name. A long descriptive name is better than a long descriptive comment. (p.39)

  • Flag arguments are ugly. Passing a boolean into a function is a truly terrible practice. It immediately complicates the signature of the method, loudly proclaiming that this function does more than one thing. (p.41)

  • Duplication may be the root of all evil in software. Many principles and practices have been created for the purpose of controlling or eliminating it. (p.48)

오늘 읽은 소감은? 떠오르는 생각을 가볍게 적어보세요

  • 함수는 한가지일을 해야한다. 이것을 Single Level Abstraction 이라고 부른다. 하지만 현실적으로 코드를 짜다보면 한가지 함수가 많은 일을 해야 일을 빨리 끝낼수 있으므로 Multi Level Abstraction 을 사용하는 경우가 많다. 이럴경우에 많은 일을 하는 함수를 짠다음 코드가 잘 돌아가는지 확인이 된다음에 한가지일을 할수 있게 바꾸는게 좋을것 같다.

  • 변수를 만들거나 함수를 만들때는 그 변수나 함수가 무엇을하는지 설명하는 이름으로 만들어야 한다. 코드를 보는 제삼자가 이름자체에서 한번에 변수와 함수가 무엇인지 알수 있으면 이해 하기 위해서 들이는 시간을 줄일수 있고 또한 개발자는 코멘트에 들이는 수고를 줄일수 있으므로 시간적인 효율을 올릴수 있다.

  • 함수 자체가 반복적인 코드를 줄이기 위해서 만들었다. 그런데 함수 안에서 반복이 일어난다면 그것은 목적을 배반하는 행위이므로 좋은 코드가 아니다.

궁금한 내용이 있거나, 잘 이해되지 않는 내용이 있다면 적어보세요.

  • Common Monadic Forms

  • Dyadic Functions