Follow

Coding question 

Which one is clearer to you, to compare two objects :

Option A :
if (a.prop1 > b.prop1) {
return true;
} else if (a.prop1 == b.prop1) {
if (a.prop2 > b.prop2) {
return true;
} else if (a.prop2 == b.prop2) {
...
return a.lastprop > b.lastprop;
...
}
return false;

Option B:
if (a.prop1 != b.prop1) {
return a.prop1 > b.prop1;
}
if (a.prop2 != b.prop2) {
return a.prop2 > b.prop2;
}
...
return a.lastprop > b.lastprop;

Sign in to participate in the conversation
Cybrespace

the mastodon instance at cybre.space is retiring

see the end-of-life plan for details: https://cybre.space/~chr/cybre-space-eol