lua-users home
lua-l archive

Re: help with lua style and syntax

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


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.
What's wrong with
localRs485SerialInstance = openSerialInstance(localRs485DeviceName)
if not localRs485SerialInstance then
 print ("...whatever...")
 return
end
Of course, this hinges on the returnvalue of openSerialInstance being sane.

AltStyle によって変換されたページ (->オリジナル) /