1. Write Clean Code
2.
3. Writing Modular code
4. Efficient Code
5. Documentation
6. Use Version control
7. Testing
8. Logging
9. Code reviews
9.0.1. 코드리뷰의 목적
9.0.2. 코드리뷰의 적절한 질문
9.0.3. Code 리뷰 팁
- Production code : 상용서버에서 live users와 data를 처리하게 된다. reliability, efficiency 등을 만족하며 목표하는 기능에 Meet한 기능이 작동하게 하는 것을 말한다.
- Clean Code : Readable, Simple, Concise 한 코드를 말한다. Production Quality의 Clean Code는 협업과 유지보수가 쉽게 되어야 한다.
- Modular Code : functions와 Modules로 분리된 코드를 말한다. 코드를 organized, efficient, reusable 하게 만드는 것이다.
- Module: 파일의 형태이다. 재사용가능하고 캡슐화된 코드의 집합으로 다른 파일의 코드안에서 작동되게 된다.
1. Write Clean Code
변수에 의미를 갖고 명확한 이름을 준다.
별도의 Comments가 없이도 코드를 이해할 수 있도록 해야한다.
- Be descriptive and imply type : prefix를 붙여서 상태나 type에 대한 정보를 만들어 준다.
- Be consistent but clearly differentiate : 간결하고 clear하게 차이점을 들어나게 해야한다.
- Avoid abbreviations and especially single letters : 누구나 이해할수 있는 단어를 사용하고 안글자 변수는 피해라 (i,j,t 제외 -> Integer로 일반적으로 사용되는 값)
- Long names != descriptive names : 너무 설명적으로 긴 이름을 바라는 것은 아니
- Use white-space properly (Indentation and new line - 79 chars limited) : 최대 79자가 넘지않도록 한 라인을 유지해라
https://www.python.org/dev/peps/pep-0008/?#code-lay-out
PEP 8 -- Style Guide for Python Code
The official home of the Python Programming Language
www.python.org
2.
3. Writing Modular code
- Don't Repeat Yourself
- Abstract out logic to improve readability
- Minimize the number of entities (functions, classes, modules, etc)
- Functions should do one thing
- Arbitrary variable names can be more effective in certain functions (ex, arr)
- Try to use fewer than three arguments per function
4. Efficient Code
- 시간 복잡도를 최소화 한다
- 공간 복잡도를 최소화 한다
5. Documentation
- Line level: in-line comments
- function or module level: Docstrings
- project level
6. Use Version control
7. Testing
- Test-Driven development: test code를 먼저 작성한 후 개발을 진행 함으로써 기능의 정합성을 관리
- Unit Test : 독립적인 기능 테스트가 가능하다. 다른 모듈간 통합 테스트는 Integration test를 이용한다
Pytest : 파이썬의 Unit Test를 하는 Tool
8. Logging
개발된 Software가 작동하는동안 이해할 수 있는 이벤트의 Message 남기는 것
- 간결하고 Clear 하게 남겨야 한다.
- Normal Capitalization을 해야한다. (This is my....)
- 적절한 Logging Level을 선택해야 한다.
- Debug : 일어나는 모든 일을 표시
- Error : Error가 일어났을 때 표시
- Info : 일반적인 actions이 일어났을 때 표시하는 모든 정보
9. Code reviews
9.0.1. 코드리뷰의 목적
- Catch errors
- Ensure readability
- Check standards are met
- Share knowledge among teams
9.0.2. 코드리뷰의 적절한 질문
- 모듈화 되어있고 clean한 코드인가
- 효율적인 코드인가
- documentation은 효과적으로 만들어졌는가
- Test가 적절히 만들어져 있는가
- Logging이 적절한가
9.0.3. Code 리뷰 팁
- linter를 사용해라
- 이슈를 설명하고 제안을 해라
- 'I' 'You' 같은 단어를 삼가하고 목적 중심의 Comments를 해라
- Code examples을 제공해도 좋다
728x90
반응형
'AI' 카테고리의 다른 글
Sigmoid Function (0) | 2021.07.17 |
---|---|
Perceptron Algorithm 코드 (0) | 2021.07.17 |
Object Orient Programing (0) | 2021.07.04 |
AWS DeepLens 소개 (0) | 2021.07.03 |
Machine Learning 소개 (0) | 2021.07.02 |