[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: help with lua style and syntax
- From: "David Collier" <myshkin@...>
- Date: Tue, 23 Oct 2012 11:00 +0100 (BST)
> *From:* "Hisham" <h@hisham.hm>
> *To:* "Lua mailing list" <lua-l@lists.lua.org>
> *Date:* Thu, 18 Oct 2012 12:32:22 -0300
>
> On Thu, Oct 18, 2012 at 11:26 AM, Martijn van Buul
> <martijn.van.buul@ellips.nl> wrote:
> > On 10/18/2012 3:43 PM, David Collier wrote:
> >
> >> well I'm finding myself writing:
> >>
> >> do
> >> local localRs485SerialInstanceOpened
> >> localRs485SerialInstanceOpened,
> localRs485SerialInstance
> >> = openSerialInstance(localRs485DeviceName)
> >> if not localRs485SerialInstanceOpened
> >> then
> >> print("program exiting - can't open local RS485
> serial
> >> port "
> >> ..localRs485DeviceName)
> >> return
> >> end
> >> end
> >>
> >> when I could write
> >>
> >> if( not( opened, localRs485SerialInstance =
> >> openSerialInstance(localRs485DeviceName))
> >> then
> >> print("program exiting - can't open local RS485 serial
> port
> >> "..localRs485DeviceName)
> >> return
> >> end
> >>
> >> I think the 2nd is more elegant.
> >>
> >
> > I feel like your examples are contrived.
>
> It is contrived. The first one even uses longer variable names.
>
> And, also, the fact he's prefixing a lot of variables with
> "localRs485" means he should probably be reorganizing the namespace,
> by using modules, functions or simply restricting scope -- but
> really,
> if one is using a local variable in a 10-line "do" block to store a
> boolean result to openSerialInstance, does the variable need to be
> called "localRs485SerialInstanceOpened"? I think "opened" is
> understandable enough given the context! (Actually, if it was my
> code
> I would have used "ok" for this purpose.)
>
> -- Hisham
excuse me , but why are you criticising my programming style when all I
was asking for is an answer to a technical question.
I write long variable names because they please me. Others don't like it.
I find it hard to care.
Rename them x, y and z for all I care, my original question is the same
:-)
Essentially I have come to like the ability of a C assignment to be used
as a value - and if Lua could handle it, including multiple-value
assignments - which are a great feature of Lua, some of my code would
look a lot neater :-)