views:

136

answers:

3

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?

+5  A: 

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 printfto 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.

Victor Nicollet
It's much older than that, I remember seeing it at least as early as the mid-90's (I can't remember more than that though).
ergosys
The [Python `.format()` function](http://www.python.org/dev/peps/pep-3101/) also uses the `{0}` format, adopted from .NET.
KennyTM
F# brings `printf` and friends to the .NET framework. It's strongly-typed, so you get a compiler error if you try to pass a string value to a format string containing a `%d`.
Joel Mueller
@Joel Mueller : so does OCaml. Type safety on formatting strings is the best thing since sliced strongly-types bread.
Victor Nicollet
@Victor - I'm sure F# got the idea from OCaml, in fact. But I agree, I much prefer using F#'s string formatting functions to the .NET ones, even though I have easy access to both kinds.
Joel Mueller
A: 

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.

taitale
it supports named arguments and plurals, now. it came from Taligent though, see my other answer.
Steven R. Loomis
I noticed your answer, but unfortunately I can't upvote yet ;). Nice to see such a quick response from an authority on the subject too, btw.
taitale
+1  A: 

Taligent MessageFormat. 1990s. Also in JDK 1.1 (which came from Taligent) and ICU (==)

Steven R. Loomis
Some C# programmer used a time machine to seed the idea at Taligent. This is why you're not getting up-voted.
ergosys
That would explain a lot, actually. Too bad they didn't send a crate of modern SODIMMs and SATA drives with the idea. T was ahead of the platform capabilities.
Steven R. Loomis