Settings

Theme

Template Strings Make the Wrong Thing Easier

matthew.kunjum.men

5 points by lafrenierejm 2 years ago · 3 comments

Reader

charmonium 2 years ago

Generally agree, but consider the counter-example of regular expressions, where the purely in-language notation is so much more verbose than putting a string-literal of a minilanguage in the larger language. Usually, we don't need to use the larger language to dynamically generate elements in the minilanguage (most regexes are string literals).

One must consider the cost of developing/maintaining new language parsing infrastructure (main point of the blog) against the readability/conciseness/features of a new syntax (not discussed in the blog).

  • SoWhich 2 years ago

    Author here. You're definitely right that how satisfied I am with leaving a sub-language inside a string literal is significantly a function of size and "staticness". A small sql string like

      SELECT * FROM users
      WHERE date_part('month', age(users.birthday)) = 0
      AND date_part('day', age(users.birthday)) = 0
    
    is probably fine to live in your host source file rather than a different one.

    That said, I think it's also worth mentioning that Parser combinators and LR/PEG parser generators typically have very little dynamic data inputs to them, but do benefit significantly from being either a DSL/Library or living in a separate dedicated file. This progression from regex to Parser Combinator/Generator as a function of size and complexity can probably be generalized onto embedded languages writ large as to whether or not they're worth keeping in a string.

  • lafrenierejmOP 2 years ago

    As a counterpoint, consider Emacs's rx (https://www.gnu.org/software/emacs/manual/html_node/elisp/Rx...) as a direct alternative to writing regular expressions.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection