3 ms·
I still prefer this: if( b != nil && b->qid.type == a->qid.type && b->qid.path == a->qid.path && b->qid.vers == a->qid.vers && b->dev == a->de
by phoboslab 13y ago
I still prefer this:
if(
b != nil &&
b->qid.type == a->qid.type &&
b->qid.path == a->qid.path &&
b->qid.vers == a->qid.vers &&
b->dev == a->dev &&
b->type == a->type
) {
fprint(2, "cp: %s and %s are the same file\n", an, bn);
ret = 1;
}
- IvyMike 13y agoWe can go deeper... if( b != nil && b->qid.type == a->qid.type && b->qid.path == a->qid.path && b->qid.vers == a->qid.vers && b->dev == a->dev && b->type == a->type ) { fprint(2, "cp: %s and %s are the same file\n", an, bn); ret = 1; } (Lined up the "a"s to make it obvious that they're all the same.)
- deleted 13y ago[deleted]
- MindTwister 13y agoI'm not sure if you're trolling or not... but isn't that the point of the function in the first place...?
- MaulingMonkey 13y agoI'd prefer some variation on: int samedirfile( Dir *a, Dir *b ) { if( a == b ) return 1; return ( a && b ) && ( a->qid.type == b->qid.type ) && ( a->qid.path == b->qid.path ) && ( a->qid.vers == b->qid.vers ) && ( a->dev == b->dev ) && ( a->type == b->type ); } ... if( samedirfile( a, b ) ) { fprint(2, "cp: %s and %s are the same file\n", an, bn); ret = 1; }
- tricolon 13y agoI think it's fascinating that we prefer styles that are almost opposites: int samedirfile(Dir *a, Dir *b) { if(a == b) { return 1; } return (a && b) && (a->qid.type == b->qid.type) && (a->qid.path == b->qid.path) && (a->qid.vers == b->qid.vers) && (a->dev == b->dev) && (a->type == b->type); } ... if(samedirfile(a, b)) { fprint(2, "cp: %s and %s are the same file\n", an, bn); ret = 1; }
- MaulingMonkey 13y agoI'll note I actually have a slight preference for prepended continuation operators like you have, but I stick to the style used at work for the sake of my sanity in trying to write consistent code.
- drivebyacct2 13y agoI'm so, so, so glad that new languages are banning braceless if/else bodies.
- MaulingMonkey 13y agoSo how about that python? </trololololo>
- drivebyacct2 13y agoI should have of course said "some" :)
- sbmassey 13y agoPutting the &&'s at the beginning of each line makes the overall shape of the logic expression easier to percieve: you can prove they're all one big 'and' expression without having to hunt for the end of each line.