Afficher un message
Vieux 20/11/2007, 14h42   #8
Brian Adkins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: is there an nicer way for this expression?

On Nov 20, 7:38 am, Remco Hh <re...@huijdts.nl> wrote:
> hi,
> perhaps a stupid question.
>
> i do this a lot: if (foo.bar==1 or foo.bar==2)
>
> can i make this expression shorter and nicer?,
> something like if (foo.bar=1,2), which of course doesn't work


You could have:

foo.bar.equals_one(1, 2, 7)

or

equals_one(foo.bar, 1, 2, 7)

How often do you do this? Your original expression is probably more
readable if you typically only have two values to compare. If you have
three or more, a function *may* (that's why I added a param to
the above). Another option would be to create a macro in your editor
to easily type the expression with minimal keystrokes.

Brian Adkins

  Réponse avec citation
 
Page generated in 0,05457 seconds with 9 queries