[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: io.format
From:       Stephan Hennig <sh-list () posteo ! net>
Date:       2015-08-19 20:59:36
Message-ID: 55D4EE38.7020402 () posteo ! net
[Download RAW message or body]

Am 19.08.2015 um 22:37 schrieb Hisham:
> On 19 August 2015 at 16:05, Stephan Hennig <sh-list@posteo.net> wrote:
>>
>> string.format is an alien within the string library.  A better place for
>> that function were, e.g., the io library.  format() is not about
>> manipulating strings but its purpose is type conversion in preparation
>> of outputting values.
> 
> I write stuff such as ("foo = %s:%d"):format(bla, num) all the time
> and I think it's entirely logical that a function for generating
> formatted strings is called string.format (also, I wish I lived in a
> parallel universe where priorities were such that I could drop the
> parentheses around that literal string...).

I'm doing that for other string operations as well, because of the
tittle-tattled runtime benefit.[1]  But I'm explicitly not doing that
for string.format for no good reason, though.  Perhaps because for
string.format the first argument in most cases is a plain string which
needs additional parentheses, while the first argument for the remaining
string functions frequently is a variable.  The good news is, you can
adapt. :-)

Best regards,
Stephan Hennig

[1] No direct access to the string table, but an additional access to
the variable's metatable, which in turn is string again?


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic