무의미한 코드의 간단하고 흔한 사례로 조건문과 중복적 논리 구조의 남발을 꼽을 수 있다. 허
술한 논리는 곧 느슨한 정신을 표현한다. 혹은 논리 구조에 대한 이해가 없다는 뜻이다. 다음
예를 살펴보자(이때 변수
expression
은
bool
형이다).
If
(
expression
)
return true
;
else
return false
;
이 코드는 다음과 같이 더 단순하고 직관적으로 변경할 수 있다.
return expression
;
위의 코드는 간편할 뿐만 아니라 읽기도 쉬워 이해하기에 어렵지 않다. 코드라기보다는 영어
문장처럼 보여 편하게 읽을 수 있다. 그리고 눈치챘겠지만, 컴파일러는
1
비트도 신경 쓰지 않
는다. 구구절절하게 표현된 또 다른 코드의 사례를 살펴보자.
if
(
something
==
true
)
{
//…
}
이 표현보다는 다음 표현이 훨씬 낫다.
if
(
something
)
훌륭한 프로그래머 5교 수정.indd 492015. 12. 1. 오전 10:56
50
1
부
you.write(code);
이러한 예제는 매우 간단한 경우로, 실제로는 훨씬 더 정교한 구조로 만들어진다. 간단한 것을
복잡하게 만드는 프로그래머의 능력을 절대
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.