I know there's no best solution, and it's all about consistency, but curiosity is killin me.
In terms of readability, in a loop where would you position the static and dynamic value? and why is that?
left compare to right?
fruits = [apple, banana, mango];
for (i = 0; i < fruits.length; i++)
{
if('mango' === fruits[i]) {}
}
or right compare to left?
for (i = 0; i < fruits.length; i++)
{
if(fruits[i] === 'mango') {}
}
which one makes more sense or easier to read and understand? also not just the loops, just the normal comparison where one is static and the other is dynamic. how would you arrange it? does this change depends on the language you are using?
function isMango(maybeMango)
{
return 'mango' === maybeMango;
}
// or??
function isMango(maybeMango)
{
return maybeMango === 'mango';
}
also i'm not very fan of Yoda condition, aside from the feel weird readability. because i believe the moment you use it, you are not confident in your condition, like not using === or you are not 100% sure what data type you are getting.
Aucun commentaire:
Enregistrer un commentaire