[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: help with lua style and syntax
- From: Hisham <h@...>
- 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