[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Are parenthesis-free calls a Good? (was Re: patch: C-style stringlexing)
- From: Eike Decker <eike@...>
- Date: Fri, 1 Feb 2008 00:25:25 +0100
I always found the error messages that the lua compiler reports quite specific,
especially compared to other languages (like forgetting a ; in a C header
file...). There is actually only one type of error that can be really hard to
track down if lots of nested functions/loops/if blocks are involved and an
'end' keyword is missing - I always needed the longest to find the position
since there could be lot's of possible locations of that keyword.
And actually this is why I find less parentheses better, like in a case like
this
foo ("name")({bar("foo") : doo ("hu",math.min(.2,var))})
It's a bit overstressed, but I have seen such constructs in real code in
different languages and these are quite often sources of syntax error problems
(the lua syntax can't do much about it since only two parenthesis are
superfluous). If I look at my coding syntax errors that I produce, missing
parenthesis are pretty much the most often occurring syntax errors. And missing
parenthesis can also be hard to be tracked down. (LISP coders might laugh about
this whole topic...)
I heard once that some people prefer python because there is only one way how to
do it while other prefer perl because there are many ways how to do it. I think
I like lua because I can be very creative to find neat descriptive coding
styles without using too many special characters.
Jerome gave another great example what can be done with this freedom
(struct 'ModelBoneDef' {
int32 'animid';
int32 'flags'; (...))
and I have to say: Neat. It looks very C Like, yet it's plain clean lua code.
For me, as a C and Lua coder, I can read it and even use it without reading any
API description.
Yes novice user are stressed to understand what is actually going on there - and
a lot of these possible new users might hang in there and say "Ok, I'll go with
[C#|Java|PHP|...], this is way too weird". Noone can stop them from doing that!
And I don't wish to! But actually, code like this exists for my purpose - Any
new lua user can life fine without these "creative" usage of coding-paradigms -
or using them without understanding the technique behind it.
Lua is an amazing language to me because of these things and it would be less if
this freedom was not there.
Eike
> Alexander Gladysh wrote:
>
> > I personally often use such calls in my micro-DSLs. Like this:
> > foo "name"
> > {
> > bar "bar";
> > baz "baz";
> > }
>
> But could other implementations be clear without using parenthesis-free
> calls?
>
> I have to admit that the code above is easier for a non programmer to
> understand than a verbatim modification to parenthesis-free calls:
>
> foo("name")(
> {
> bar("bar")
> baz("baz")
> })
>
> But I bet the error messages are completely unintelligible! I guess a
> user would just compare against a known good example until all it works.
>
> I've recently had the displeasure of looking through a 4k-line custom
> DSL config file in order to debug a very cryptic error message. I said
> to a colleague, "Too bad it's not in Lua." Then I realized it could be a
> domain-specific language using Lua! In this particular case I doubt it.
> The problem ended up having nothing whatsoever to do with the DSL or
> config file contents.
>
> I have been able to use configuration files successfully using
> parentheses. I typically put the items directly in a table then call a
> registration function if necessary. I doubt that my problem spaces
> (embedded or scientific) are typical, though. I don't mind the
> parentheses so much since they don't really pile up to the extent that
> they do in Schlisp.
>
> All abstractions hide complexity, so in some sense my wishes are nothing
> more than a preference about where to draw the abstraction/transparency
> line. My only supporting arguments are those I mentioned initially and
> the fact that simplicity has served Lua so well in the past.
>
> >From your message posted while I composed this:
> > If they made that a syntax error and added constant folding to
> > strings we'd probably both be happy? =)
>
> Perhaps! Actually, I'm very happy with Lua as it is. Ask those around me
> who groan every time I say the word "Lua."
>
> As Roberto says, there's no need to worry. Any changes to the language
> will bend around this syntax - it is truly part of the ancient soul of Lua.
>
> Doug
>
> --
> Innovative Concepts, Inc. www.innocon.com 703-893-2007 x220
>