ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Chapter 2. Object-Oriented Programming - 1
    algorithms-in-python 2017. 7. 15. 22:29

    2.1.3 Design Patterns

    the algorithm design patterns

    - Recursion, Amortization, Divide-and-conquer, Prune-and-search, Brute force, Dynamic programming, The greedy method

    the software engineering design patterns

    - Iterator, Adapter, Position, Composition, Template method, Locator, Factory method


    2.2 Software Development

    - 일반적인 소프트웨어 개발은 다음의 단계를 거친다. 1) 디자인    2) 구현    3) 테스팅 & 디버깅

    2.2.1 Design

    - OOP(object-oriented programming)에 기초해서 소프트웨어를 개발할 때, 가장 중요한 단계는 디자인 단계다. 프로그램을 여러 개의 클래스로 어떻게 나눌지, 각각의 클래스들은 서로 어떻게 소통할지, 각각의 클래스가 저장할 정보는 무엇인지, 각각의 클래스가 어떤 기능을 지원하게 할지 정하는 작업이 이에 해당한다. 초보 프로그래머들이 프로그램을 짤 때 가장 어려워하는 부분도 바로 클래스를 정의하는 것이다. 

    - **책에서는 Responsibilities, Independence, Behaviors의 용어로 약간의 원칙을 추상적으로 제시하고 있지만, 너무 추상적이어서 이해를 구체화하는 데에는 도움이 되지 않으므로 이부분은 생략하겠다. 

    - 클래스를 정의하고, 멤버 변수와 메소드를 정의하는 것이, OOP 디자인의 핵심이다. 좋은 프로그래머들은 시간이 지나면 자연스럽게 이러한 능력을 키우게 된다.


    2.2.3 Coding Style and Documentation

    - Programs should be made easy to read and understand

    - pylint라는 게 있다. (Pylint is a source code, bug and quality checker for the Python programming language. It follows the style recommended by PEP 8, the Python style guide.)

    - https://www.pylint.org/

    - Ubuntu에서는 'sudo apt-get install pylint'로, OS X에서는 'pip install pylint'로 설치할 수 있다. 

    몇 가지 컨벤션을 소개하면 다음과 같다.

    * Use meaningful names for identifiers. Try to choose names that can be read aloud, and choose names that reflect the action, responsibility, or data each identifier is naming.

    - 클래스는 단수명사(singular-noun)의 형태로 쓰여야 하고, 첫글자가 대문자여야 한다. CamalCase convention을 따른다.(e.g., CreditCard)

    - 모든 함수는 소문자로 쓴다. 여러 단어가 합쳐진 경우, 언더바('_')로 연결해준다.  (e.g., make_payment) 

    - 함수의 경우, 클래스와는 다르게 동사(Verb)로 쓴다. 그러나 함수의 목적이 그냥 특정 값을 return하는 것일 경우 동사형 대신 명사형을 쓰기도 한다. (e.g., sqrt rather than calculate sqrt).

    - 상수를 지시하는 identifier의 경우, (e.g., MAX_SIZE) 이런 형태로 쓴다. 

    - Identifiers in any context that begin with a single leading underscore (e.g., _secret) are intended to suggest that they are only for "internal" use to a class or module, and not part of a public interface.

    * Documentation

    - Python provides integrated support for embedding formal documentation directly in source code using a mechanism known as a docstring. Formally, any string literal that appears as the first statement within the body of a module, class, or function(including a member function of a class) will be considered to be a docstring.

    - It is common to use the triple-quoted string delimiter for a docstring, even when the string fits on a single line.

    - the command help(x), within the Python interpreter, produces the documentation associated with the identified object x. 


    2.2.4 Testing and Debugging

    - Testing is the process of experimentally checking the correctness of a program.

    - Debugging is the process of tracking the execution of a program and discovering the errors in it. 









Designed by Tistory.