Live data from Hacker News

Ifs and &&s and Plan 9's Source Code

computationallyendowed.com

131–140 of 150 posts

Re: Ifs and &&s and Plan 9's Source Code

#131
post #112

How about using this alternative form: 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; } It keeps almost the same visual look and it uses the common convetion, except for the && at the beginning of each line.

Using ifs is definitely more readable than &&, words always win. However carefully alignment of && and ( can make things better. Note that the comment after "if" is necessary to keep the shape balanced. if( /* b is same as a */ (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 sam…

"words always win"

Add seven to three then multiply the whole thing by twelve.

(7 + 3) * 12

Re: Ifs and &&s and Plan 9's Source Code

#132

It looks weird without tabbing. But if the code was tabbed, then it would take too much space, since they are using huge tabs. That's why I prefer 3-space tabs. Not too small, not too big.

Following typical layout rules, there's a much easier way to get this conjunction without indents:

if(foo == bar

        && baz == qux

        && ! frob

        && whatever()

        && something) {

Re: Ifs and &&s and Plan 9's Source Code

#133
post #124

Earlier quoted context omitted.

Makes me wonder what the quality of the architecture is on your projects is though. Not that I think coding style is unimportant, but it's all too easy to criticize yesteryear's code with today's style standards and totally miss the forest for the trees. Are you doing work that measures up to the ambition of Plan 9?

We all know how well that ambition turned out.

Yes, (1) commercially it went nowhere, (2) technically it's a complete working os with original ideas implemented in a masterful way. Not bad I think!

Re: Ifs and &&s and Plan 9's Source Code

#134
I think the meaning was fairly obvious at first glance, and it read as a sloppy way of conjoining expressions, where && should be preferred, because it doesn't rely on the arbitrary block rules of if expressions.

Imagine for a moment that a stray ";" ends up at the end of one of those if statements. I don't care how, perhaps you just dropped your Warby Parkers on your keyboard or something. Not only is the code now broken, but it still compiles. With &&, it would fail to compile and the error would be caught immediately.

The moral of the story is that syntax is your friend, not your enemy. Use syntax as much as possible to catch errors. Especially with strictly-typed languages, you have an incredible tool for automated verification of certain portions of your program. Use it.

Re: Ifs and &&s and Plan 9's Source Code

#135
I actually quite like that, although usually when I have a large conditional like that I just give it named boolean variables to make it read more like a sentence, IE:

    bool exists = b != nil;
    bool sameType = b->qid.type == a->qid.type;
    bool samePath = b->qid.path == a->qid.path;
    ...
    if(exists && sameType && samePath) {
    }
It's also a lot easier to inspect in a debugger, as all the conditions appear in the locals list.

Re: Ifs and &&s and Plan 9's Source Code

#136

I actually quite like that, although usually when I have a large conditional like that I just give it named boolean variables to make it read more like a sentence, IE: bool exists = b != nil; bool sameType = b->qid.type == a->qid.type; bool samePath = b->qid.path == a->qid.path; ... if(exists && sameType && samePath) { } It's also a lot easier to inspect in a debugger, as all the conditions appear in the locals list.

You could also group related conditions, so that nested if's don't bloat the locals so much:

    speedIsSlow = dict(downstreamSlow = downstreamSpeed  100
        if connectionIsDead:
                print("It's dead, Jim")

Re: Ifs and &&s and Plan 9's Source Code

#137
post #133
post #124

Earlier quoted context omitted.

We all know how well that ambition turned out.

Yes, (1) commercially it went nowhere, (2) technically it's a complete working os with original ideas implemented in a masterful way. Not bad I think!

I can say the same for many other OSs, like BeOS or Native Oberon, just to name two of them, but in the end it is (1) that counts.

It is like football, it does not matter how brilliant a team plays, but which one has higher score when the referee signals the end of the game.

Re: Ifs and &&s and Plan 9's Source Code

#139
post #124

Earlier quoted context omitted.

Makes me wonder what the quality of the architecture is on your projects is though. Not that I think coding style is unimportant, but it's all too easy to criticize yesteryear's code with today's style standards and totally miss the forest for the trees. Are you doing work that measures up to the ambition of Plan 9?

We all know how well that ambition turned out.

You know what never fails though? The middlebrow dismissal!

Re: Ifs and &&s and Plan 9's Source Code

#140
post #137
post #133

Earlier quoted context omitted.

Yes, (1) commercially it went nowhere, (2) technically it's a complete working os with original ideas implemented in a masterful way. Not bad I think!

I can say the same for many other OSs, like BeOS or Native Oberon, just to name two of them, but in the end it is (1) that counts. It is like football, it does not matter how brilliant a team plays, but which one has higher score when the referee signals the end of the game.

IMHO, (1) is the not only think that counts in the end. A 'failed' (as in (1)) concept may have a second life in future works. Also, in the case of plan9 some ideas did get traction (UTF-8 for example), some didn't so it's not all bad. Comparisons are tricky, you can compare an OS to a football team, and then yes maybe what you say is right. Or you can compare it to a work of art, then what matters is the influence the works has in shaping the future...
Post reply on HN