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: 217

This is a question about preferences.

Assume a programming language offers these two options to make a string with some variables:

  1. "Hello, my name is ". name ." and I'm ". age ." years old."
  2. 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

Related posts about strings

Related posts about code-formatting