←back to thread

620 points tambourine_man | 1 comments | | HN request time: 0.234s | source
Show context
serbuvlad ◴[] No.43750075[source]
All things considered, this is pretty cool. Basically, this replaces

    db.execute("QUERY WHERE name = ?", (name,))
with

    db.execute(t"QUERY WHERE name = {name}")
Does the benefit from this syntactic sugar outweigh the added complexity of a new language feature? I think it does in this case for two reasons:

1. Allowing library developers to do whatever they want with {} expansions is a good thing, and will probably spawn some good uses.

2. Generalizing template syntax across a language, so that all libraries solve this problem in the same way, is probably a good thing.

replies(12): >>43750226 #>>43750250 #>>43750260 #>>43750279 #>>43750513 #>>43750750 #>>43752117 #>>43752173 #>>43752293 #>>43754738 #>>43756560 #>>43763190 #
mikeholler ◴[] No.43752117[source]
A potential concern is how close this looks to the pattern they're trying to override.

    db.execute(f"QUERY WHERE name = {name}")
versus

    db.execute(t"QUERY WHERE name = {name}")
replies(2): >>43752225 #>>43753358 #
fzzzy ◴[] No.43752225[source]
But won't the f string version fail loudly because there's no name parameter?
replies(1): >>43752231 #
benwilber0 ◴[] No.43752231[source]
the {name} parameter is in the locals() dict like it always is
replies(1): >>43752248 #
fzzzy ◴[] No.43752248[source]
Good point. Perhaps the database api could refuse strings and require Templates.
replies(1): >>43753252 #
bshacklett ◴[] No.43753252[source]
That’s a big breaking change around a brand new feature. I’m sure it could be done well, but it gives me the shivers.
replies(2): >>43755459 #>>43769208 #
1. dragonwriter ◴[] No.43769208[source]
You add a new API that takes templates only leaving the existing API in place. You (some releases later) deprecate the string API. You (some releases later, with clear advance warning of when it is coming) actually remove the deprecated API. "It's a big breaking change around a brand new feature", yeah, so you don't break anything around a brand new feature, it's not like this kind of transition is a new concept.