String Formatting with concatenation or substitution
Posted
by
Davio
on Programmers
See other posts from Programmers
or by Davio
Published on 2013-11-01T12:38:49Z
Indexed on
2013/11/01
16:20 UTC
Read the original article
Hit count: 246
This is a question about preferences.
Assume a programming language offers these two options to make a string with some variables:
"Hello, my name is ". name ." and I'm ". age ." years old."
StringFormat("Hello, my name is $0 and I'm $1 years old.", name, age)
Which do you prefer and why?
I have found myself using both without any clear reason to pick either. Considering micro-optimizations is not within the scope of this question.
Localization has been mentioned as a reason to go with option #2 and I think it's a very valid reason and deserves to be mentioned here.
However, would opinions differ based on aesthetic viewpoints?
© Programmers or respective owner