loading...

Discussion on: I'm a senior developer and I regularly google "html image tag"

Collapse
tailcall profile image
Anton Istomin

Yesterday I googled how to concatenate strings in Swift. Yes, it was "+", like in almost every other language I worked with, and yet I wasn't sure.

Collapse
justinledwards profile image
Justin Edwards

I prefer string interpolation on languages that support it.

let multiplier = 3
let message = "\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)"
// message is "3 times 2.5 is 7.5

Collapse
tailcall profile image
Anton Istomin

I agree, string interpolation is cool, but sometimes I feel that some simple operations are more readable if you just use concatenation, like when adding a prefix to a string.

let prefixedString = prefix + string
// versus
let prefixedString = "\(prefix)\(string)"

When my brain sees latter, it thinks "oh, some serious formatting is probably going on here, I should totally spend time and energy to carefully investigate it".