SlideShare a Scribd company logo
Load to
Clean Code
한셀팀 l 2016.09.21
1.각항목당내용확인
2.각항목당내용토의(Q&A)
3
나쁜 코드
• 르블랑의 법칙
나중은 결코 오지 않는다.
• 태도
나쁜 코드의 책임은 프로그래머에게 있다.
• 원초적 난제
기한을 맞추기 위한 나쁜 코드 양산
하지만 나쁜 코드는 업무 속도를 늦춘다
4
깨끗한 코드
• 한가지를 제대로 하는 코드
• 단순하고 직접적인 코드
• 문학적인 읽기 쉬운 코드
• 중복이 없고 표현력이 높으며 작은 추상화
• 읽기 : 쓰기 = 10 : 1
읽기 쉬운 코드여야 쓰기 쉽다
• 보이스카우트 규칙
캠프장은 처음 왔을 때보다 더 깨끗하게 해놓고 떠나라.
5
깨끗한 코드
• 의도를 분명히 밝혀라
• 그릇된 정보를 피하라
• 의미 있게 구분하라
• 발음하기 쉬운 이름을 사용하라
• 검색하기 쉬운 이름을 사용하라
• 인코딩을 피하라
• 자신의 기억력을 자랑하지 마라
• 클래스 이름
6
의미 있는 이름
7
의미 있는 이름
• 메서드 이름
• 기발한 이름은 피하라
• 한개념에 한 단어를 사용하라
• 말장난을 하지마라
• 해법 영역에서 가져온 이름을 사용하라
• 문제 영역에서 가져온 이름을 사용하라
• 의미 있는 맥락을 추가하라
• 불필요한 맥락을 없애라
8
함수
• 작게
• 더 짝께
• 한 가지만 해라! (한가지를 '잘'!)
• 함수 당 추상화 수준은 하나로!
• 위에서 아래로 코드읽기: 내려가기 규칙
• 서술적인 이름을 사용하라!
9
함수 인수
• 가능한 적은 인수 (늘어난다면 묶도록)
• 프래그 인수 (불값은 함수의 할일이 많다는 의미)
• 동사와 키워드
10
함수
• 명령과 조회를 분리 (불분명한 용도)
• 반복하지 마라
• 구조적 프로그래밍 (입구와 출구는 하나!)
11
변수
• 변수는 내버려두면 계속 늘어난다
• 가볍게 -> 가독성
- 방해되는 변수를 제거
- 변수의 범위를 축소
- 값이 한번 만 할당되는 변수를 선호 : const, final
12
주석
• 주석은 나쁜 코드를 보완하지 못한다
이런! 주석을 달아놔야겠네! -> 아 코드좀 정리해야지..
• 코드로 의도를 표현하라!
13
좋은 주석
• 법적인 주석
• 정보를 제공하는 주석
• 의도를 설명하는 주석
• 의미를 명료하게 밝히는 주석
• 결과를 경고하는 주석
• TODO 주석
• 중요성을 강조하는 주석
• 주절거리는 주석
• 같은 이야기를 중복하는 주석
• 오해할 여지가 있는 주석
• 의무적으로 다는 주석
• 이력을 기록하는 주석
• 있으나 마나 한 주석
• 위치를 표시하는 주석
14
나쁜 주석
15
나쁜 주석
• 닫는 괄호에 다는 주석
• 공로를 돌리거나 저자를 표시하는 주석
• 주석으로 처리한 코드
• 너무 많은 정보
• 모호한 관계
16
형식 맞추기
• 파일 길이는 짧게
• 적절한 행 길이를 유지하라
• 개념은 빈 행으로 분리하라
• 수직거리
• 변수는 사용한 위치 가까이
• 인스턴스 변수를 모으자
• 종속된 함수 / 개념적 유사한 함수는 가까이
17
객체와 자료 구조
• 자료 추상화
• 모듈은 자신이 조작하는 객체의 속사정을 몰라야 한다.
18
오류 처리
• NULL 을 반환하지 마라 (Exception 을 사용 등)
• NULL 을 전달하지 마라
19
냄새와 휴리스틱 (쉬운 방법,지름길,어림짐작
법)
• 조건을 캡슐화
if(shouldBeDeleted(timer)) is better then
if(timer.hasExpired() & !timer.isRecurrent())
• 부정 조건은 피하라 (가독성/이해)
if(!list.empty()) -> if(list.notEmpty())
• 경계 조건을 캡슐화 하라 (i+1 index+1 ... -> nextindex = i+1)
Q/A

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Load to Clean code

  • 3. 3 나쁜 코드 • 르블랑의 법칙 나중은 결코 오지 않는다. • 태도 나쁜 코드의 책임은 프로그래머에게 있다. • 원초적 난제 기한을 맞추기 위한 나쁜 코드 양산 하지만 나쁜 코드는 업무 속도를 늦춘다
  • 4. 4 깨끗한 코드 • 한가지를 제대로 하는 코드 • 단순하고 직접적인 코드 • 문학적인 읽기 쉬운 코드 • 중복이 없고 표현력이 높으며 작은 추상화
  • 5. • 읽기 : 쓰기 = 10 : 1 읽기 쉬운 코드여야 쓰기 쉽다 • 보이스카우트 규칙 캠프장은 처음 왔을 때보다 더 깨끗하게 해놓고 떠나라. 5 깨끗한 코드
  • 6. • 의도를 분명히 밝혀라 • 그릇된 정보를 피하라 • 의미 있게 구분하라 • 발음하기 쉬운 이름을 사용하라 • 검색하기 쉬운 이름을 사용하라 • 인코딩을 피하라 • 자신의 기억력을 자랑하지 마라 • 클래스 이름 6 의미 있는 이름
  • 7. 7 의미 있는 이름 • 메서드 이름 • 기발한 이름은 피하라 • 한개념에 한 단어를 사용하라 • 말장난을 하지마라 • 해법 영역에서 가져온 이름을 사용하라 • 문제 영역에서 가져온 이름을 사용하라 • 의미 있는 맥락을 추가하라 • 불필요한 맥락을 없애라
  • 8. 8 함수 • 작게 • 더 짝께 • 한 가지만 해라! (한가지를 '잘'!) • 함수 당 추상화 수준은 하나로! • 위에서 아래로 코드읽기: 내려가기 규칙 • 서술적인 이름을 사용하라!
  • 9. 9 함수 인수 • 가능한 적은 인수 (늘어난다면 묶도록) • 프래그 인수 (불값은 함수의 할일이 많다는 의미) • 동사와 키워드
  • 10. 10 함수 • 명령과 조회를 분리 (불분명한 용도) • 반복하지 마라 • 구조적 프로그래밍 (입구와 출구는 하나!)
  • 11. 11 변수 • 변수는 내버려두면 계속 늘어난다 • 가볍게 -> 가독성 - 방해되는 변수를 제거 - 변수의 범위를 축소 - 값이 한번 만 할당되는 변수를 선호 : const, final
  • 12. 12 주석 • 주석은 나쁜 코드를 보완하지 못한다 이런! 주석을 달아놔야겠네! -> 아 코드좀 정리해야지.. • 코드로 의도를 표현하라!
  • 13. 13 좋은 주석 • 법적인 주석 • 정보를 제공하는 주석 • 의도를 설명하는 주석 • 의미를 명료하게 밝히는 주석 • 결과를 경고하는 주석 • TODO 주석 • 중요성을 강조하는 주석
  • 14. • 주절거리는 주석 • 같은 이야기를 중복하는 주석 • 오해할 여지가 있는 주석 • 의무적으로 다는 주석 • 이력을 기록하는 주석 • 있으나 마나 한 주석 • 위치를 표시하는 주석 14 나쁜 주석
  • 15. 15 나쁜 주석 • 닫는 괄호에 다는 주석 • 공로를 돌리거나 저자를 표시하는 주석 • 주석으로 처리한 코드 • 너무 많은 정보 • 모호한 관계
  • 16. 16 형식 맞추기 • 파일 길이는 짧게 • 적절한 행 길이를 유지하라 • 개념은 빈 행으로 분리하라 • 수직거리 • 변수는 사용한 위치 가까이 • 인스턴스 변수를 모으자 • 종속된 함수 / 개념적 유사한 함수는 가까이
  • 17. 17 객체와 자료 구조 • 자료 추상화 • 모듈은 자신이 조작하는 객체의 속사정을 몰라야 한다.
  • 18. 18 오류 처리 • NULL 을 반환하지 마라 (Exception 을 사용 등) • NULL 을 전달하지 마라
  • 19. 19 냄새와 휴리스틱 (쉬운 방법,지름길,어림짐작 법) • 조건을 캡슐화 if(shouldBeDeleted(timer)) is better then if(timer.hasExpired() & !timer.isRecurrent()) • 부정 조건은 피하라 (가독성/이해) if(!list.empty()) -> if(list.notEmpty()) • 경계 조건을 캡슐화 하라 (i+1 index+1 ... -> nextindex = i+1)
  • 20.
  • 21.
  • 22. Q/A