On 2012-02-20 21:25, Nick Sabalausky wrote:
"H. S. Teoh"<[email protected]>  wrote in message
news:[email protected]...
On Mon, Feb 20, 2012 at 08:36:56PM +0100, Andrej Mitrovic wrote:
On 2/20/12, Juan Manuel Cabo<[email protected]>  wrote:
will be trouble. Instead please do:

         "The '%1$s' file's size is %2$d which is wrong"


That is the shittiest formatting specifier ever invented. The
unreadability of it is why I never, ever, use it. Python solved this
nicely with its {0} {1} syntax:

print '{0} and {1}'.format('foo', 'bar')

Actually, even that isn't ideal. How is the translator to know what on
earth {0} and {1} are? Sometimes you need to know in order to make a
good translation. This would be even better:

"The ${file}'s size is ${size}, which is wrong"

The usefulness of named arguments is even more apparent in complex
message like this one:

"${file}:${line}: Expecting ${expectedtoken}, got ${inputtoken}"

Without named parameters, you'd have:

"{0}:{1}: expecting {2}, got {3}"

which is almost impossible to translate. What are {0} and {1}? What are
{2} and {3}? Does it mean "12:30pm: expecting program to succeed, got
general protection fault"?

Using named parameters makes it clear this is a parser error, not
something else. This difference may mean using a completely different
grammatical structure to translate the message.


vote++; I've been drooling over the idea of named argument format strings in
D for a long while.

I also agree with posix-style specifiers being barely readable. I fell in
love with C#'s "Hello {1}" style at first sight, and was thrilled that Tango
adopted it. Then I moved to Phobos2, and have been missing those wonderful
curly braces ever since.

Tango doesn't even require you put a number in the parameter, just "Hello {}". It is still possible to put a number if you want, something like this "Hello {2} {1} {1}".

--
/Jacob Carlborg

Reply via email to