3 ms·
print($"My name is ^(@name).") I don't understand why anyone would still require special notation for interpolated strings, when we have the awesome and unambi
by tomp 10y ago
print($"My name is ^(@name).")
I don't understand why anyone would still require special notation for interpolated strings, when we have the awesome and unambiguous string interpolation syntax introduced by Swift (granted, this project was started in 2011, before Swift).
> Reference counting has the benefit of giving consistent, and more easily measured performance. There's no fear of the garbage collector suddenly leaping into action right at the worst time, or having to tune the collector to minimize pauses.
LoL. Refcounting can lead to just as long pauses as GC, if your reference is the last reference to a huge object graph.
- jesserayadkins2 10y agoTo my understanding, Swift wasn't public for a long time. The idea behind requiring a special syntax for interpolation is that it's supposed to be more clear as to do you really want interpolation, or do you not actually want it. I'm :/ about the interpolation syntax right now. One thing I wanted to avoid is telling people "oh no your string never terminated." You're right about reference counting being able to pause. But that's something you're more able to control. If you're doing game dev, you can say "I won't assign to references that might be big" during frame critical code. With garbage collection, you're more or less "Run the gc before, hope it doesn't trigger during that critical spot." or the alternative of fiddling with the gc/manually firing it off so it doesn't stop your world when it's a bad time to stop the world.
- Nullabillity 10y ago> print($"My name is ^(@name).") > > I don't understand why anyone would still require special notation for interpolated strings, when we have the awesome and unambiguous string interpolation syntax introduced by Swift (granted, this project was started in 2011, before Swift). Why should the swift syntax be considered the default now? "My name is $blah." has been the de-facto standard for ages. Personally I like interpolation sigils since in most cases you don't actually use it, and languages like Scala allow you to define custom sigils with custom behaviour. For example, Slick defines a sql"SELECT * FROM table WHERE username=$username" syntax that does not cause SQL injection issues.
- berdario 10y agoSwift string interpolation syntax is not more awesome or any less ambiguous than other syntaxes used in other languages In fact, it's the first time that I've seen interpolation with round parentheses, rather than curly braces (which are used in javascript with $ (es2015 template literals), python, bash with $, ruby with #, groovy with $, etc... ) > LoL. Refcounting can lead to just as long pauses as GC He didn't say more performant, he said consistent
- tomp 10y ago(1) It's obviously less ambiguous, because you can't do it accidentially; "\(" is an invalid escape, whereas "${1}" or "$a" is a valid string (i.e. you could write it without meaning to interpolate the variables). (2) It's only consistent if you always know what your pointers are pointing at, and whether your pointers are the last reference to it... but then you can just use delete, right?
- berdario 10y ago(1) you're confusing C string and other languages strings (even Swift strings are not the same thing as NSString or C strings). Anyhow, even in C \( is perfectly accepted by compilers gcc -Wall -x c - <<EOF #include <stdio.h> int main(){ printf("\(hi"); } EOF So it's perfectly reasonable to write it and not mean interpolation (maybe they meant "\\(", but that's another matter) (2) A sequence can be sorted without you knowing which elements are inside it, A computation can be known to terminate without you knowing (yet) which value it will yield. Similarly, you don't need to have internal knowledge of your code to know that you'll be able to rely on RC consistency in the future (otoh I guess that something consistent is not necessarily the same as something predictable)
- hk__2 10y ago> Anyhow, even in C \( is perfectly accepted by compilers Even if it’s accepted it’s not valid, at least in the C99 standard.
- vorg 10y ago
- reitanqild 10y ago> LoL. Refcounting can lead to just as long pauses as GC, if your reference is the last reference to a huge object graph. Laughing out loud is fine I guess but it adds nothing to this discussion as that paragraph would easily stand on its own or even be better without.