Hi,
maybe you would find
return result = getValue if result
clearer?
In any case I find the tryreturn idiom awkward and unnecessary.
Also I agree with you that using an assignment in an if is not clear
and should be avoided, as for short temp name, nothing prevents you
from using longer ones, personally the only time I tend to use such short
names are in languages without iterator support for simple (read not nested)
for loop indexes and I agree I shouldn't but old habits die hard.
Benoit
"Juha Pohjalainen" <voidjump / nic.fi> wrote in message
news:20010530083405.C15296 / lanfear.nic.fi...
> On Wed, May 30, 2001 at 07:41:25AM +0900, Wayne Blair wrote:
> > I always had a love/hate relationship with the efficient but cryptic:
> >
> > if (x=getValue) return x
>
> More recently my love/hate relationship with such code has turned
> to be hate/hate relationship. :-(
>
> First, I don't like using too short and meaningless variable names.
> Secondly, above code opens up possibility for errors like:
> if (x==getValue) return x
>
> That is, if you come later back to that code (or someone
> else comes back) one year later, and have to change something,
> meaning of original code might have been forgotten and cryptic
> code does not help.
>
> > I like the idea of creating something less cryptic and just as
efficient,
> > but your implementation doesn't seem to make it less cryptic or more
> > efficient.
>
> I think it is less cryptic, because it states your intention. (And
> if someone comes up with better english word for it, then more it
> states the intention of code and not side effects; my native
> language is finnish, so coming up with english words is not my
> strongest point.)
>
> I think it is more efficient, because no need for temporary variable.
>
> > Here is the traditional way of doing it:
> >
> >  | def doSomethingWith value
> >  |   if (result = tryFirstThing value) then return result
> >  |   makeSomePreparations value
> >  |   if (result = trySomethingElse value) then return result
> >  |   raise TypeError, "could not do it"
> >  | end
> >
>
> Traditional way of doing things is not always the right way. Or
> we could still be using punchcards (or no computers at all in
> our caves).
>
> > Wayne
>
> "Have a great day", says Jippo
>
> --
>  __________________________________________________________________
> [   pub 1024/951AFAF5 1995/12/12   Juha Pohjalainen <jmp / iki.fi>   ]
> [   fingerprint 41 56 7F F9 8E EC 16 35  BB 42 EF A7 DF 19 FA 31   ]
> [__ http://www.iki.fi/jmp/ ________________ GSM +358 40 570 1179 __]