lua-users home
lua-l archive

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


Great !
There is a difference between "readable" and "in one line". Assume
the following string:
...
What is more readable, (1) or (2) (see below)?

I agree with that (1) is more readable of course.  But usually, when I output the quoted string,  I'm intending to find something important to make sure things got controlled, not really want to know what the whole string exactly means.  Mostly, I already know what it is.
Certainly, there IS exceptions, for example:
    "#define SOMEMACRO somecode \
             someothercodes"
'\' has it's own means, even if it's not a source codes. But it's lua, right? We lua users all know what happend to this quoted string, I mean,  if it's really a string made by lua and by q option of string.format. I should pray for a clear thinking and spirits to face this after a long long searching work on a huge log file or complex and scrolling debug outputs with quoted, unquoted, lua, non-lua strings and non-strings.

Generally,  strings with un-escaped characters are not for common users out of lua, if I need to show something to them, q option is definitely not the best choice. So I believe the pages like (1) is pretty rarely seen in real life.

But for programmers,  as I said before, (2) is clearly the best choice.

I mean, '%q' is an very useful tools,  because string tricks are so important for lua programmers, but it never just a tool that making things with good looking.
It's more useful and powerful and should be a tool for un-escaping escapable chars (I think) other than for printing.  "\<newline>" just always screwed things up anyway.

"#define SOMEMACRO somecode \nsomeothercodes" and "#define SOMEMACRO somecode \10someothercodes" are both acceptable.
> Of course, in this case, even better would be the original form, with
> [[...]] (and multiple lines!). One size does not fit all needs, but it
> is very easy to use 'gsub' to do the formatting the way it pleases you.
It does is easy, if you insist. But I think it's easier to change some lua source code my self, and it's not really easy at all to change it everytime lua changes, haha.