Just curious about this in the history of development... how did brackets with the array index ({0}
, {1}
, and so on) become the standard of string formatting?
Any special significance, or something somebody picked out of midair in the 80's?
Just curious about this in the history of development... how did brackets with the array index ({0}
, {1}
, and so on) become the standard of string formatting?
Any special significance, or something somebody picked out of midair in the 80's?
Actually, back in the 80's, the formatting string standard was printf
, with format strings such as %d
for integers or %s
for strings, and obscure format modifiers (such as %06d
which draws an integer and pads it to the left with zeros until it reaches six characters). The reasoning was that the C type system was very poor, and it was impossible for printf
to guess what the data it received was (was it a pointer to a string? an integer? a floating-point number) which made it necessary to specify the type of the arguments inside the format string. This approach remained.
This format was carried over from C (and C++) to many languages (Java, PHP, OCaml, Scilab...) and several tools (Firebug's console.log
function, for instance).
The earliest I've seen the {0}
format was in C#, in the early 2000s. I haven't seen it a lot outside C# so far.
I'm not sure whether it is the actual origin, but the ICU (International Components for Unicode) project uses curly braces in message formatting and was first released as open source in 1999. To my knowledge it is not a standard, but it is nice to have some form agreement on the handling of Unicode text formatting between different programming languages (at least implementations/bindings exist for C++, Java and PHP (not sure about C#)). You can read more about the entire project at userguide.icu-project.org.
Taligent MessageFormat. 1990s. Also in JDK 1.1 (which came from Taligent) and ICU (==)