Redowan's Reflections
Hi, I’m Redowan.
A roving amateur fumbling through software, systems, and sundry.
Recent writing
Implement Rust-style Result types for type-safe exception handling in Python using generic Ok and Err types inspired by Black formatter.
Understand covariance, contravariance, and invariance in Python generics with practical examples of type relationships and subtyping rules.
Optimize Python dictionary slicing from O(DK) to O(K) complexity using direct key lookups instead of iterating through all items.
Avoid Python function default argument pitfalls caused by early binding, where mutable defaults and function calls bind at definition time.
Test literal booleans correctly in Python unittest using assertIs instead of assertTrue/assertFalse to avoid truthy/falsy confusion.
Type Python decorators accurately using ParamSpec and Concatenate to preserve wrapped function signatures and enable proper static analysis.
View Python docstrings from the command line with pydoc or serve them as HTML documentation for modules, classes, and functions.
Use Python's bit_count() method to elegantly check if an integer is a power of two by counting on-bits in binary representation.
Standardize Django REST Framework error responses using custom exception handlers to match Microsoft's REST API guidelines format.
Understand when to use constrained TypeVar vs Union in Python type hints for consistent types across function parameters and return values.
Avoid memory leaks when caching instance methods with lru_cache by making cache containers local to instances instead of global.
Crop text to character limits without breaking words using Python's textwrap.shorten for clean truncation with customizable placeholders.
Learn how Python's string interning optimizes memory by caching strings and using sys.intern() for custom string caching to improve performance.
Implement Go-style structural subtyping in Python with Protocol for duck typing and interface-based APIs without inheritance dependencies.
Implement automatic attribute delegation in Python composition using __getattr__ magic method for inheritance-like attribute access patterns.