✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more
Andrii Bidochko
  • Updated: February 27, 2026
  • 5 min read

BPatterns: A Smalltalk DSL for Rewrite Engine

BPatterns is a Smalltalk‑native DSL that wraps the powerful AST‑level rewrite engine in an easy‑to‑read block syntax, letting developers match and transform code without memorising cryptic string patterns.


BPatterns diagram

Why BPatterns Matters for Modern Smalltalk Development

Since its debut alongside the Refactoring Browser, the Smalltalk rewrite engine has offered unparalleled AST‑matching capabilities. Yet its string‑based syntax has remained a barrier for many developers. BPatterns eliminates that friction by providing a fluent, block‑based API that integrates seamlessly with standard Smalltalk tooling. The result is a more maintainable, discoverable, and IDE‑friendly way to perform code transformations, deprecations, and automated refactorings.

Overview of BPatterns and Its Purpose

BPatterns was created to address three core pain points:

  • Obscure syntax: Traditional rewrite rules live inside quoted strings, making them invisible to code navigation tools.
  • Limited IDE support: No code completion, syntax highlighting, or refactoring assistance for pattern definitions.
  • Steep learning curve: Developers often spend more time recalling pattern syntax than actually writing transformations.

By turning a pattern into a regular Smalltalk block, BPatterns lets you leverage the full power of the development environment—browsers, inspectors, and refactorings—all while keeping the underlying rewrite engine intact.

Key Features and Syntax Examples

Below are the most compelling capabilities of BPatterns, illustrated with concise code snippets.

1. Block‑Based Pattern Declaration

Define a pattern by sending #bpattern to a block. Wildcards are any identifier that starts with any or any_.

[ anyReceiver isNil ifTrue: anyBlock ] bpattern

2. Fluent Rewrite Syntax

Combine a match pattern with a rewrite block using the -> operator.

[
    anyReceiver isNil ifTrue: anyBlock
] bpattern -> [
    anyReceiver ifNil: anyBlock
] brewrite

3. Explicit Variable Constraints

Refine wildcards with #with: and custom filter blocks.

[
    anyVar isNil ifTrue: anyBlock
] bpattern with: [ anyVar ] -> [:pattern |
    pattern beInstVar where: [:v | v name beginsWith: 'temp']
] brewrite

4. Selector Wildcards and Keyword Renaming

Match any part of a selector and rewrite it to a new keyword.

[
    anyReceiver anyKeywordPart: anyArg1 staticPart: anyArg2
] bpattern -> [
    anyReceiver newKeywordPart: anyArg1 staticPart: anyArg2
] brewrite

5. Binary Message Filtering

Target binary messages with a simple filter.

[
    any anyMessage: any2
] bpattern with: #anyMessage: -> [:p | p beBinary] browseUsers

6. Integration with Existing Tools

While BPatterns works out‑of‑the‑box, it also plays nicely with Pharo’s StRewriterMatchToolPresenter and the Glamorous Toolkit. You can invoke the same match‑and‑rewrite pipelines from the UI or from scripts.

Tooling and Integration Details

UBOS has embraced BPatterns as part of its UBOS platform overview. The integration enables developers to embed rewrite logic directly into low‑code workflows, making automated code upgrades a first‑class citizen of the platform.

Key integration points include:

  • Workflow Automation Studio: Use BPatterns inside Workflow automation studio to trigger refactorings after a CI build.
  • Web App Editor on UBOS: The Web app editor on UBOS now offers a “Pattern‑Based Refactor” widget that generates BPattern code from UI selections.
  • Template Marketplace: Several ready‑made templates leverage BPatterns, such as the AI SEO Analyzer and the AI Article Copywriter. These templates demonstrate how pattern matching can automate content‑generation pipelines.

Because BPatterns is pure Smalltalk, you can also combine it with other UBOS integrations like Telegram integration on UBOS or the OpenAI ChatGPT integration to create bots that self‑update their own codebase.

Benefits for Developers

Adopting BPatterns yields tangible productivity gains across the software lifecycle.

  • Reduced Cognitive Load: No need to memorize back‑tick syntax; patterns read like ordinary Smalltalk code.
  • Full IDE Support: Syntax highlighting, code completion, and refactoring tools work natively.
  • Safer Refactorings: The underlying rewrite engine validates AST matches, preventing accidental mismatches.
  • Reusable Libraries: Patterns can be packaged as reusable modules, shared across teams via the UBOS portfolio examples.
  • Accelerated Deprecation: Combine BPatterns with the upcoming deprecation API (original blog post) to automatically replace obsolete messages across a codebase.
  • Scalable Automation: When paired with the Enterprise AI platform by UBOS, patterns can be executed at scale on thousands of repositories.

Real‑World Use Cases

Below are three scenarios where BPatterns shines.

A. Automated API Migration

When a third‑party library changes its method signatures, a BPattern can locate every old call and rewrite it to the new form, all without manual search‑and‑replace.

B. Enforcing Coding Standards

Define a pattern that matches any method lacking a self reference in a specific context, then rewrite it to include the missing reference, ensuring consistency across the codebase.

C. Generating Boilerplate Code

Use BPatterns to detect repetitive scaffolding patterns and replace them with calls to UBOS UBOS templates for quick start, dramatically cutting development time.

Getting Started with BPatterns on UBOS

Follow these steps to integrate BPatterns into your next project:

  1. Visit the UBOS homepage and sign up for a free developer account.
  2. Navigate to the UBOS pricing plans to select a tier that includes the Workflow automation studio.
  3. Open the Web app editor on UBOS and create a new BPattern block.
  4. Test your pattern using the built‑in #browseUsers method to preview matches.
  5. Deploy the rewrite as part of a CI pipeline using the UBOS partner program integration hooks.

Conclusion & Call to Action

BPatterns bridges the gap between the raw power of Smalltalk’s rewrite engine and the everyday needs of developers who value readability, tooling, and maintainability. By adopting BPatterns within the UBOS ecosystem, you gain a modern, AI‑ready workflow that scales from startups to enterprise‑grade applications.

Ready to supercharge your codebase?

Join the community, contribute patterns, and let BPatterns become the backbone of your next refactoring revolution.


Andrii Bidochko

CTO UBOS

Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.

Sign up for our newsletter

Stay up to date with the roadmap progress, announcements and exclusive discounts feel free to sign up with your email.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.