4 ms·
Even if eager evaluation it's already a very compelling way of managing basically every lightweight "templating" for safety: e.g. embedded dynamic HTML or SQL.
by masklinn 2y ago
Even if eager evaluation it's already a very compelling way of managing basically every lightweight "templating" for safety: e.g. embedded dynamic HTML or SQL. `markupsafe` is great, but it's way too easy to perform formatting before calling it, especially with f-strings.
That f-strings were "static" was by far my biggest criticism of it, given how useful I find JS's template strings.
And this proposal seems like a straight up better version of template strings:
- the static strings and interpolations are not split and don't have to be awkwardly re-interpsersed which I've never found 100% trouble and 0% utility
- the lazy evaluation means it can be used for things like logging (which really want lazy evaluation), or meta-programmation (because you can introspect the callables, and you get the expression text)
- codethief 2y ago> - the lazy evaluation means it can be used for things like logging (which really want lazy evaluation) Could you elaborate? I would find it rather surprising if my log messages don't contain the data at the very moment I invoke the logger.
- masklinn 2y agoThe expressions for the data you want to log out can be expensive, so ideally you only want to compute them after you’ve checked if the logger was enabled for the level you need. In most APIs this requires an explicit conditional check and the average developer will not think of it. This allows said check to be performed internally.
- skywhopper 2y agoYou can’t get log4j-style security crises with eager evaluation.