Re: Readability question.

Sean Conner <[email protected]> Fri, 5 Jun 2026 16:11:47 -0400
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
It was thus said that the Great Francisco Olarte once stated:
> Hello Martin.
> 
> On Fri, 5 Jun 2026 at 19:06, 'Martin Eden' via lua-l
> <[email protected]> wrote:
> > On 2026-06-05 16:11, Francisco Olarte wrote:
> > It still bad for me:
> 
> "Para gustos los colores", we say around here. But I'll try to spain.
> 
> >    if a == nil then
> >       return b
> >    end
> >    if b == nil then
> >       return a
> >    end
> > We're testing for one thing and returning other.
> 
> Which is typical when testing for "badness", I read this as "if a is
> bad, use b, if b is bad, use a, if both are good, use both". It lacks
> an "if both are bad" at the start, which I could use too, but it is
> not relevant in this case. In fact every usage of 'return a and b',
> 'return a and b or c', even 'return a or b' depending on how yoou look
> at it, tests one thing and return ( or uses if you are doing a
> parameter pass or assignment ) other.

  I would write this as:

	if a then
	  if b then
	    return combine(a,b) -- a b
	  else
	    return a -- a /b
	  end
	elseif b then
	  return b -- a /b
	else
	  return -- /a /b
	end
	
I personally don't like comparing directly against nil unless 'false' is a
valid thing to return (for instance, a = false b = nil).  But that aside,
this reads better to me as if we have an a and not a b, we return a.  I've
marked the four cases this covers (where /a means "not a").

  -spc

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/20260605201147.GA1582%40brevard.conman.org.