Programming

    [Python] 파이썬 3.11 기능 소개

    [Python] 파이썬 3.11 기능 소개

    Introduction 파이썬 3.10 기능 소개를 한 지 얼마 지나지 않은 것 같은데, 슬슬 3.11 버전에 대한 소식도 들려오고 있다. 이번 글에서는 3.10 버전과 비교해 3.11 버전에서는 어떤 기능들이 새롭게 추가 되었는지 소개하고자 한다. 이 글은 3.11.0b4 릴리즈를 기준으로 한다. 설치는 이 링크를 참고하자. 예제와 표의 일부는 공식 도큐멘테이션에서 참고했다. (이전 글) [Python] 파이썬 3.10 기능 소개 1. Faster CPython 파이썬 3.11 버전은 이전 버전에 비해 (3.10) 전반적인 실행 속도가 10%~60% 정도, 평균적으로는 25% 정도 빨라졌다고 한다. 설명만으로는 와닿지 않으니 한번 테스트를 해 보자. import time def timer(functio..

    [Python] overrides 라이브러리 (리스코브 치환 원칙)

    [Python] overrides 라이브러리 (리스코브 치환 원칙)

    Introduction 파이썬에서 클래스 계층 구조를 확장시키다 보면 부모 클래스의 메서드를 오버라이딩 (overriding) 해야 할 일이 분명히 있을 것이다. 오버라이딩이란 부모 클래스를 상속받는 자식 클래스에서, 부모 클래스에서 이미 정의된 메서드를 새로 정의하는 행위를 뜻한다. 아래의 코드를 참고하자. class FooClass(): def __init__(self): pass def foo_function(self): print("Foo function.") return class FooChildClass(FooClass): def __init__(self): pass # Method overrided. def foo_function(self): super().foo_function() prin..

    [Design patterns] Singleton Pattern (싱글턴 패턴)

    [Design patterns] Singleton Pattern (싱글턴 패턴)

    Introduction Design Patterns: Elements of Reusable Object-Oriented Software (1994) 의 저자인 Erich Gamma 는 책이 출판된 15년 후의 인터뷰에서 이렇게 언급한 적이 있다. Larry: How would you refactor "Design Patterns"? Erich: ... When discussing which patterns to drop, we found that we still love them all. (Not really — I'm in favor of dropping Singleton. Its use is almost always a design smell.) 의역하자면 다음과 같다. Larry: "Design P..