Patterns in Finance and Indexing 01

First, the adapter pattern should be implemented to standardize the data feed intake. It is crucial to establish a uniform method, such as data_provider.get_price("AAPL"), to accommodate the various API formats provided by different vendors. class BloombergAPI: def getField(self, ticker, field): return f"Bloomberg {ticker}:{field}=185.5" class FactSetAPI: def get_price(self, ticker): return f"FactSet {ticker}=185.5" # Unified interface class … Continue reading Patterns in Finance and Indexing 01

Building a Library System to Apply Software Engineer Thinking

From procedural → class-based → design-pattern-level architecture, developing a library system serves as a profound method to implement software engineering principles. Jumping to stage 2 that is class-based as the following, note the three classes are too tightly coupled, not an ideal practice:class Book: def __init__(self, title, author): self.title = title self.author = author self.is_borrowed … Continue reading Building a Library System to Apply Software Engineer Thinking

Python Literacy Continue 3

The Interpreter Pattern: Defining a Language The Interpreter pattern is used to define a grammar for simple languages and implement an interpreter to process sentences in that language. It's ideal for domain-specific languages (DSLs), mathematical expressions, or simple configuration rules. How it Works: The grammar is defined using a class hierarchy where each rule or … Continue reading Python Literacy Continue 3

Python Literacy Continue 1

This blog post summary covers several key object-oriented programming (OOP) and design principles, with a focus on Python implementation and idiom. Class Construction and Separation of Concerns Internal vs. External Data: When constructing a class, data passed as arguments from the user (like initial values) are external. Internal operational data, such as a running count … Continue reading Python Literacy Continue 1

Advanced Python Features

Summary: Top 18 Advanced Python Concepts #ConceptLocationWhy Important1Async Context Managerclient.py:55-78Resource lifecycle2Dataclass field()types.py:37Mutable defaults3post_inittypes.py:132Auto-validation4Enum(str, Enum)types.py:17JSON-serializable enums5Union (AB)client.py:366isinstance type guardsclient.py:144Type narrowing7Literal typestypes.py:84Exact value constraints8Callable/Awaitabletypes.py:90Async callback types9Private methods (_)client.py:198API encapsulation10Defensive copyclient.py:333Prevent mutation11Error-as-valueclient.py:141-192Railway-oriented design12@staticmethodengine.py:20Pure functions13dict.get()engine.py:84Safe access14perf_counter()client.py:139High-precision timing15Observer patternclient.py:198-239Hook system16Module structureinit.pySeparation of concerns17Relative importsclient.py:12Package portability18Builder patterntypes.py:104Flexible configuration One by one analysis: First Async Context Manager for example class CalculatorClient: def … Continue reading Advanced Python Features