4 ms·
This reminds me of Swift's string formatting syntax: let name = "Bob" print("Hi my name is \(name)") Which I always quite liked. I found myself missing th
by gh123man 6y ago
This reminds me of Swift's string formatting syntax:
let name = "Bob"
print("Hi my name is \(name)")
Which I always quite liked. I found myself missing this when I moved on to Rust and Go.
- ausbah 6y agoKotlin is even simpler with statements like "hello $variable" or "hello ${function()}"
- blackrock 6y agoThis overloads the backslash \(). Which is usually used for escaping characters. Like, \n for new line. So, you may end up with code like: print(“Hi. \nMy name is \(name).”)
- Someone 6y agoAnd do you think that’s good or bad? I think it’s nice that there is only one escape character. You check for ‘\’. If it’s there, switch on the next character checking for ‘n’, ‘t’, ‘r’ or ‘(‘, defaulting to appending the unmodified character to the output. I think that might not only be simpler, but also be slightly faster than having having two different escapes would be.
- saagarjha 6y agoI think the intent here is that you are escaping into an interpolation context…
- ibraheemdev 6y agoThe implicit formatting arguments RFC has been merged [0], so you will be able to write this in Rust soon: let name = "Bob"; print!("Hello {name}"); [0]: https://rust-lang.github.io/rfcs/2795-format-args-implicit-identifiers.html https://rust-lang.github.io/rfcs/2795-format-args-implicit-i...
- kzrdude 6y agoThat's a surprise, I thought we were firmely against that. :)