lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Aug 21, 2015 at 4:05 AM, John Hind <john.hind@zen.co.uk> wrote:
>> Responding to (the Great) Sean Conner, Thu, 20 Aug 2015 12:47:14 -0400:
>>  I'm not sure what your point is here.  Yes, this:
>>
>>       syslog('emergency',"%s stat(%q) = %s",dbtype,conf.file,errno[err])
>>
>>could be replaced with:
>>
>>       syslog('emergency',dbtype .. ' stat("' .. conf.file .. '") = ' ..
> errno[err])
>
> I really could not have come up with a better example myself! Frankly the
> second
> Version "expresses intent" *much* more clearly than the first. I would have
> to
> look up "%q" in a reference manual and the whole pattern concept is opaque
> unless you are steeped in "C". In the second version all you need to know is
> the meaning of ".." which is easily guessable from context. Also you do not
> have to worry about accidental escapes in the string literals (except for
> quote
> marks of course, which would remain a complexity).

Clearly you have never worked with internationalized code. The second
example would get my code rejected for sure if I submitted it in a
professional context.

Sure, for syslog, you can get away with it. But if your strings are
user-facing and you ever want to ship in more than one language,
breaking the format string apart makes translation a much clumsier
process, if it's even possible at all. Having it as a single string
means that the translator can (1) see the entire statement being
translated, and (2) position the placeholders appropriately in the
output.

Yes, internationalization is more complicated than that (in practice,
%s is insufficient and you need named or positional parameters, and
then plurals and gender make a mess of things) but format strings are
utterly fundamental to doing it right.

/s/ Adam