Dev Blog

The Programming Jottings

Go vs Python - A Deep Dive into String Length

In the programming world, strings are one of the most common data types. However, different programming languages can have significant differences in how they handle strings. Today, we’ll delve into the distinction between Go and Python in processing string lengths, a seemingly simple concept that reveals important differences in language design philosophy. Case Study Let’s start with a simple example: s := "Hello, 世界! 👋" This string contains ASCII characters, Chinese characters, and an emoji....

August 9, 2024 · aaron

functools

functools provides a range of features that can greatly simplify your code and make it more efficient. The functools module is part of the Python standard library and provides higher-order functions, decorators, and other utilities for working with functions. functools.partial: Partial Function Application Partial function application is a technique where you create a new function by fixing certain arguments of an existing function, allowing you to provide only the remaining arguments when calling the new function....

December 5, 2023 · aaron

Pydantic Library

Pydantic Library Pydantic v2 is a powerful data validation and serialization library for Python. It leverages Python’s type hints to provide runtime data validation, making your code more robust and easier to maintain. Installation To install Pydantic, use pip: pip install pydantic For email validation, you can install the optional email-validator dependency: pip install pydantic[email] Basic Concepts Models Pydantic models are classes that inherit from BaseModel and define fields with type annotations....

October 21, 2023 · aaron

List of Design Patterns

Creational patterns Factory Method: Define an interface for creating a single object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. Abstract Factory: Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Builder: Separate the construction of a complex object from its representation, allowing the same construction process to create various representations. Prototype: Specify the kinds of objects to create using a prototypical instance, and create new objects from the ‘skeleton’ of an existing object, thus boosting performance and keeping memory footprints to a minimum....

May 20, 2023 · aaron

Visitor Pattern

The Visitor pattern is a behavioral pattern that separates an algorithm from an object structure on which it operates. The pattern allows you to add new operations or algorithms to an object structure without modifying the structure itself. The pattern achieves this by defining a separate object called a visitor, which can traverse an object structure and apply a specific operation to each element of the structure. The main idea behind the Visitor pattern is to provide a way to separate the concerns of an algorithm from the object structure it operates on....

May 20, 2023 · aaron