Skip to the content.
The Power of Formatting Wrappers: Keep It Simple | AI Systems Design From Scratch

Connect with Amin Boulouma Official

AI Systems Design From First Principles - An implementation of AI Systems Design From First Principles | Product Hunt

🏠 Documentation Hub 📝 Engineering Blog 💻 GitHub Repository

The Power of Simple Wrappers

Amin Boulouma, Software Engineer

The _wrap function is an excellent example of micro-utility design. While it is deceptively simple, it follows a core principle of software engineering: Do one thing, and do it well.

def _wrap(self, text, marker):
    return "{}{}{}".format(marker, text, marker)

Why This Pattern Matters

This function is a “text decorator.” It decouples the intent of wrapping a string from the implementation of the string formatting itself.

1. Readability vs. Inline Operations

You could easily write f"{marker}{text}{marker}" everywhere you need this logic. However, creating a method named _wrap elevates the code from “string manipulation” to “an operation with a clear intent.”

2. Ease of Maintenance

If you ever decide that you need to add logic to this—perhaps to escape special characters or add whitespace—you only have to update the code in one place:

def _wrap(self, text, marker):
    # Now this utility can grow without breaking call sites
    clean_text = str(text).strip()
    return f"{marker}{clean_text}{marker}"

The “Wrapper” Pipeline

In larger systems, these functions act as nodes in a pipeline. You might use them to prepare data for markdown rendering, logs, or UI displays.

When to Use This Approach

Pro-Tip: Modern Formatting

While .format() is standard, for modern Python (3.6+), using f-strings is generally preferred for performance and readability:

def _wrap(self, text, marker):
    return f"{marker}{text}{marker}"

Connect with Amin Boulouma Official