4 ms·
I think having multiple processors is very smart exactly due to the outlined reason - making sure the interpolated result is safe for the system that will consu
by bruce343434 3y ago
I think having multiple processors is very smart exactly due to the outlined reason - making sure the interpolated result is safe for the system that will consume that string, be it a query language or json or something else.
f"" vs STR."" is really a quite minimal difference, and I think worth it. Having the "." operator here mean "interpolate RHS using LHS" seems a nice balance between terseness and explicitness.
As for "\{" being a divergent choice, frankly who cares.
- whartung 3y agoThese are some good examples: var $ = STR; var $h = new HtmlTemplateThing(); var $j = new JSONTemplateThing(); var name = "John"; var s = $."Hello \{name}"; // HTML escaped var h = $h."<b>\{name}</b>"; // JSON escaped var j = $j.""" { "name" : "\{name}" } """; // JSON escaped I love this one: var $db = new DBConnectionTemplateThing(); // SQL Escaped and processed PreparedStatement st = $db."select * from table where name = '\{name}'"; Or: var $x = new XMLTemplateThing(); // XML escaped and parsed Document d = $x."<xml>\{name}</xml>"; This is pretty powerful. They selected \{ for the start of expressions because of the legacy of Java Expression Language (EL) which came from JSP and JSF. Doesn't look that terrible to me.
- dfinninger 3y ago“\{“ reminds me of Swift’s “\(“. So I wouldn’t think it’s even that divergent. And Java devs are already used to backslashes peppering strings (me included). https://developer.apple.com/documentation/swift/stringinterpolationprotocol https://developer.apple.com/documentation/swift/stringinterp...