vendredi 9 juin 2017

Is instantiating an array in condition a bag programming habit?

I often see this kind of condition :

if ([CONSTANT_1, CONSTANT_2, CONSTANT_3].contains? var && a_boolean) #...

instead of :

if ((var == CONSTANT_1 || var == CONSTANT_2 || var == CONSTANT_3) var && a_boolean) #...

I understant that the first condition is more elegant, but does creating an array only to check a condition is bad or does the resource used are negligible enough to be ignored ?

Aucun commentaire:

Enregistrer un commentaire