Working on Pharo Smalltalk: BPatterns: Rewrite Engine with Smalltalk Style

Fans cheer simpler code rewrites, skeptics say it’s just macros with lipstick

TLDR: BPatterns turns Pharo’s cryptic rewrite rules into simple, readable blocks. Commenters are split between “finally usable” cheers and “it’s still macro-hard” warnings, with one noting that pattern “holes” are tricky in complex languages—important because it could make powerful code changes less painful for everyday developers.

Smalltalk world just got a drama drop: BPatterns promises to tame the infamous, string-based rewrite engine in Pharo by letting you write find-and-replace rules as normal code blocks. Translation for the non-nerds: fewer weird symbols, more readable “search and swap” for your code. The crowd? Loudly split. Old-timers who’ve suffered the backtick bingo cheered, calling it “finally usable.” Others rolled their eyes: isn’t this just fancy wrapping around the same beast? One commenter compared it to Lisp-style macros (code that writes code), warning that letting people carve “holes” in code patterns is always tricky and can get messy fast. The memes flew fast: jokes about “backtick PTSD,” “keyboard yoga,” and “two kinds of quotes, one kind of headache.” Still, fans hyped the real win: because BPatterns are just regular code, you get autocomplete, navigation, and refactoring—the basic comforts everyone wanted but the old system hid inside strings. Purists countered with a classic gatekeep: learn the original syntax; it’s powerful for a reason. Pragmatists shot back: power is worthless if no one remembers how to use it. Whether you call it a gentle on-ramp or lipstick on a macro, BPatterns has the vibe of a much-needed quality-of-life mod for Pharo, and the comments are eating it up.

Key Points

  • The Smalltalk rewrite engine (from the Refactoring Browser, 1997) offers powerful AST-level matching and rewriting but uses string-based syntax that is hard to recall.
  • BPatterns introduces a Smalltalk-native DSL using blocks as patterns, created via the #bpattern message, with an “any” prefix denoting wildcards.
  • BPatterns builds a pattern AST using the rewrite engine’s classes, preserving original matching/rewriting capabilities while improving usability and tooling support.
  • Developers can find matches (browseUsers) and perform rewrites (brewrite preview) directly from blocks without specialized tools like StRewriterMatchToolPresenter.
  • Patterns can be refined with #with: and filters (e.g., beVariable, beInstVar, beLocalVar), and custom constraints can be applied via where: blocks without relying on raw strings.

Hottest takes

"This is roughly the same problem as syntactical macros" — jaen
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.