Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

is it ok to do this

Name: Anonymous 2007-06-23 13:51 ID:6CyOAcE6

instead of

int f(a) {
if(a == 3) return 1
else return 0;
}

to write

return (a == 3);

? thanks in advance

Name: Anonymous 2007-06-23 14:36 ID:T9xsbd5/

>>1

not only it is ok, it's the right way to do it. Anything else is wrong.
Not only that, but suppose you want to return something like

if (a == 3) return 'a';
else return 'b';

it's not the proper way to do it. The proper way is to use the ternary operator, ?:, like this

return a == 3 ? 'a' : 'b';

the same goes for stuff like

if (a == 3) then val = 4;
else val = 10;

you better write

val = (a == 3 ? 4 : 10);

the same goes if you have something like

if (a == 3)
f(a,b,c,d,e,f);
else
f(a,b,c,d,e,g);

just write
f(a,b,c,d,e, a == 3 ? f : g);
it's cleaner, believe me.


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List