Python으로 배우는 소프트웨어 공학 원칙
Adam Spannbauer
Machine Learning Engineer
import this
The Zen of Python, by Tim Peters (abridged)
아름다움이 추함보다 낫다.
명시는 암시보다 낫다.
단순함이 복잡함보다 낫다.
복잡함은 난해함보다 낫다.
가독성이 중요하다.
구현을 설명하기 어렵다면, 나쁜 아이디어다.
구현을 설명하기 쉽다면, 좋은 아이디어일 수 있다.
좋지 않은 이름짓기
def check(x, y=100):
return x >= y
설명적인 이름짓기
def is_boiling(temp, boiling_point=100):
return temp >= boiling_point
과도한 이름짓기
def check_if_temperature_is_above_boiling_point(
temperature_to_check,
celsius_water_boiling_point=100):
return temperature_to_check >= celsius_water_boiling_point
The Zen of Python, by Tim Peters (abridged)
단순함이 복잡함보다 낫다.
복잡함은 난해함보다 낫다.

def make_pizza(ingredients):
# Make dough
dough = mix(ingredients['yeast'],
ingredients['flour'],
ingredients['water'],
ingredients['salt'],
ingredients['shortening'])
kneaded_dough = knead(dough)
risen_dough = prove(kneaded_dough)
# Make sauce
sauce_base = sautee(ingredients['onion'],
ingredients['garlic'],
ingredients['olive oil'])
sauce_mixture = combine(sauce_base,
ingredients['tomato_paste'],
ingredients['water'],
ingredients['spices'])
sauce = simmer(sauce_mixture)
...
def make_pizza(ingredients):
dough = make_dough(ingredients)
sauce = make_sauce(ingredients)
assembled_pizza = assemble_pizza(dough, sauce, ingredients)
return bake(assembled_pizza)
좋지 않은 이름짓기
def check(x, y=100):
return x >= y
설명적인 이름짓기
def is_boiling(temp, boiling_point=100):
return temp >= boiling_point
과도한 이름짓기
def check_if_temperature_is_above_boiling_point(
temperature_to_check,
celsius_water_boiling_point=100):
return temperature_to_check >= celsius_water_boiling_point
Python으로 배우는 소프트웨어 공학 원칙