티스토리 뷰

728x90
반응형

들어가기

개발자로 살아간다면 좋은 코드에 대한 고민은 끝없이 해야 한다고 한다.

그래서인지 이와 관련된 서적도 많이 있다.

내가 추천받은 책들은

개발자의 글쓰기 (김철수 저 | 위키북스 | 2019년 10월 04일 출간) 

Clean Code 클린 코드 (로버트 C. 마틴 저  | 박재호, 이해영 역 | 인사이트 | 2013년 12월 24일)

 

나중에 기회가 된다면 읽고 꼭 후기를 남기도록 하겠다.

그렇다면 이제 좋은 코드란 무엇인지 알아보도록 하자.

 

 

좋은 코드란?

1. 적절한 Comment 를 사용한 코드

코멘트를 남발하면 가독성이 떨어지지만, 기능마다 주의해야 할 점을 적어두면 도움이 된다.

 

2. 이름을 잘 지은 코드

다른 사람이 보았을 때, 이 변수나 함수 등이 어떤 기능을 하는지 이름만 보아도 알 수 있게 이름을 짓자.

그러나 너무 긴 이름은 가독성이 떨어지니 전체적인 코드의 흐름 안에서 충분히 구체적이고 간결하게 짓자.

 

특히 식별자 설정 시 밑에 기법들을 사용하여 나타내니 알아두자. 

변수 설정 기법은 아래 4가지가 있다.

 

1)카멜 표기법(Camel Case)

- 식별자 표기 시에 여러 단어가 이어지면 첫 단어 시작만 소문자로 하고 나머지 각 단어의 첫 글자는 대문자로 지정하는 표기법

- ex)newList

 

2)파스칼 표기법 (Pascal Case)

- 식별자 표기 시에 여러 단어가 이어지면 각 단어의 첫 글자는 대문자로 지정하는 표기법

- ex)NewList

 

3)스네이크 표기법 (Snake Case)

- 식별자 표기 시에 여러 단어가 이어지면 단어 사이에 언더바'_' 를 넣는 표기법

- ex)new_list

 

4)헝가리안 표기법 (Hungarian Case)

- 식별자 표기 시에 맨 앞에 자료형을 붙이는 표기법

- ex)정수형일 경우 : nScore

 

3. 스타일 가이드 참고하기

(찾아보고 싶은 언어명) style guid 를 검색해보자. ex) python style guid

아래는 내가 참고하려고 넣어둔 링크!

 

- 파이썬

https://www.python.org/dev/peps/pep-0008/

 

PEP 8 -- Style Guide for Python Code

The official home of the Python Programming Language

www.python.org

https://github.com/google/styleguide/blob/gh-pages/pyguide.md

 

google/styleguide

Style guides for Google-originated open-source projects - google/styleguide

github.com

 

- 자바

https://www.oracle.com/technetwork/java/codeconvtoc-136057.html

https://google.github.io/styleguide/javaguide.html

 

Google Java Style Guide

1 Introduction This document serves as the complete definition of Google's coding standards for source code in the Java™ Programming Language. A Java source file is described as being in Google Style if and only if it adheres to the rules herein. Like ot

google.github.io

 

- 자바스크립트

 

https://standardjs.com/

 

JavaScript Standard Style

JavaScript Standard Style Sponsored by     English • Español (Latinoamérica) • Français • Bahasa Indonesia • Italiano (Italian) • 日本語 (Japanese) • 한국어 (Korean) • Português (Brasil) • 简体中文 (Simplified Chinese) •

standardjs.com

https://github.com/airbnb/javascript

 

airbnb/javascript

JavaScript Style Guide. Contribute to airbnb/javascript development by creating an account on GitHub.

github.com

https://google.github.io/styleguide/jsguide.html

 

Google JavaScript Style Guide

Google JavaScript Style Guide 1 Introduction This document serves as the complete definition of Google’s coding standards for source code in the JavaScript programming language. A JavaScript source file is described as being in Google Style if and only i

google.github.io

 

- C

https://www.doc.ic.ac.uk/lab/cplus/cstyle.html

 

Recommended C Style and Coding Standards

Recommended C Style and Coding Standards L.W. Cannon R.A. Elliott L.W. Kirchhoff J.H. Miller J.M. Milner R.W. Mitze E.P. Schan N.O. Whittington Bell Labs Henry Spencer Zoology Computer Systems University of Toronto David Keppel EECS, UC Berkeley CS&E, Univ

www.doc.ic.ac.uk

 

- C++

https://google.github.io/styleguide/cppguide.html

 

Google C++ Style Guide

 

google.github.io

 

- C#

https://google.github.io/styleguide/csharp-style.html

 

C# at Google Style Guide

Style guides for Google-originated open-source projects

google.github.io

 

4. 구조화 하기. 

구조화를 잘 하려면 파일 분리(관련된 코드를 필요한 만큼 한곳에 모아두는 것)를 잘해야 한다.
이 부분은 객체지향 프로그램을 활용하면 된다.
또한 상황과 필요에 따라서 선택적으로 디자인 패턴을 이용하여 코드를 짜자.
디자인 패턴과 관련된 책은 아래를 참고하자.

GoF의 디자인 패턴 (에릭 감마 저 | 김정아 역 | 프로텍미디어 | 2015년 03월 26일) 

 

 

글을 마치며

좋은 코드를 쓰기 위해 더 참고할 만한 것들은 아래와 같다. 

1.훌륭한 개발자들의 코드 참고

2.라이브러리 내부 코드 및 공식 홈페이지 참고

3. 공식 개발 문서 참고

밑에는 언어들의 공식개발 문서이다. 

참고해서 좋은 코드를 쓰는 개발자가 되자!

 

Python - https://docs.python.org/ko/3/

Javascript - https://developer.mozilla.org/ko/docs/Web/JavaScript/Guide

Ruby- https://www.ruby-lang.org/ko/documentation/

Java- https://docs.oracle.com/en/java/

728x90
반응형
댓글