변수의 선언 부분과 정의 부분을 같은 위치에 쓰라. 코드 이해에 필요한 노력을 최소화하고 초
기화되지 않은 변수로 인한 잠재적 에러를 줄이기 위함이다. 사실 이런 변수들이 무의미할 때
도 있다. 다음 예를 살펴보자.
bool a
;
int b
;
a
=
fn1
();
b
=
fn2
();
if
(
a
)
foo
(
10
,
b
);
else
foo
(
5
,
b
);
이 코드는 다음과 같이 훨씬 짧고 명확하게 바꿀 수 있다.
foo
(
fn1
()
?
10
:
5
,
fn2
());
3.7
나쁜 설계
물론 불필요한 코드는 낮은 수준의 실수나 부적절한 관리로 인한 결과물로 치부될 수는 없다.
높은 수준의 설계상의 결점 탓일 수도 있기 때문이다.
나쁜 설계는 분명한 이유 없이 수많은 여분의 데이터를 정렬하는 것과 같은, 컴포넌트 간의 불
필요한 의사소통을 초래할 수 있다. 데이터가 많아질수록 더 많은 오류가 발생할 것이다.
시간의 흐름과 더불어, 컴포넌트는 사용되지 않는 많은 코드를 남겨둔 채로 원래의 의도와 다
훌륭한 프로그래머 5교 수정.indd 582015. 12. 1. 오전 10:56 ...
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.