lua-users home
lua-l archive

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


It was thus said that the Great John Hind once stated:
> >Date: Sat, 22 Aug 2015 17:08:14 -0400
> >From: Sean Conner <sean@conman.org>
> 
> >I'll give "complex" a pass (given the the modifiers you can add), but
> >where do you get "arbitrary" from?
> 
> >	%d - decimal output of a number
> >	%o - octal output of a number
> >	%x - hexidecimal output of a number
> >	%s - string
> >	%f - float
> >	%q - quoted string
> 
> I'll give you a reciprocal pass on "arbitrary" then (though why 'x' for
> hexadecimal rather than 'h'?). My point is: why does this syntax not
> aspire to the same degree of readability as the rest of Lua? I do not
> think a proposal to shorten ALL of Lua's keywords to one letter prefixed
> by a randomly selected punctuation symbol (what have percentages got to do
> with string formatting?) would be considered sensible! (OK, I've just
> taken back my pass on "arbitrary"!)

  I'm not sure why 'x'.  I can make an educated guess though---it stands
out.  C allows hexidecial literals in source code, and it was chosen that
the format for that would be 0x0.  Perhaps the creators of C found 0h0 to be
harder to see 0X0 0x0 0H0 0h0 ... in any case, since hexidecimal literals
use 0x, why not use %x in formatting strings?

> >Also, a format string does make it easier to handle translations. 
> >Granted, this is geared more for compiled languages like C where (depending
> >on the platform) it might be impossible to load variations on code (like a
> >shared library [1]) but it can also be applied to languages like Perl, Lua,
> >Ruby or Python.
> 
> I get why C did this (especially in conjunction with the "resource" system
> in Windows EXE files, which supported positional tokens long before
> Python)), but it is not necessary in a scripting language. It is just as
> easy (and much more flexible) to write a translation support tool that
> emits Lua source for functions in a table as strings in a table.

  And Python, and Perl, and Ruby, and PHP, and Javascript ... 

> >  -spc (Why the hate for format strings?  Did printf() bite you as a kid?)
> 
> It still bites me every day! It (plus regular expressing patterns, string
> literal escapes and now pack/unpack codes) are the only things I have to
> dig out a reference manual for every time I use them. It does not help
> that the Lua reference manual can't be bothered to document format strings
> completely, referring out to "the ISO C function sprintf", so now I need a
> C reference to hand as well as a Lua one!

  Recall that Lua was meant to be embedded in a C program, so it doesn't
seem unreasonable to me that knowledge of C would be expected.  Also, I've
been programming in C for over twenty years and I *still* have to look up
the format strings for strftime() *every damn time I use that function*. 
And I still have to play around with syntax when I want to use ... and I
keep forgetting the name ... anonymous pointers?  

	rc = setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(int){1},sizeof(int));

instead of

	int opt = 1;
	rc = setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(int));

Annoying, but I live with it.

  -spc