Live data from Hacker News

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

computationallyendowed.com

31–40 of 150 posts

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

#31
Oh god that code is fucking hideous.

If someone who worked with me wrote that I'd talk to them about it and make sure they never did anything like that ever again.

From the terrible argument names to the abuse of the single line if syntax (which should never be used anyway, always use curly braces.)

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

#33

As a side note: if(b->qid.path==a->qid.path) is interesting. This is not how you compare strings in C. So it is either a bug or dirstat() needs to guarantee that different results pointing to the same file always share the path string.

This line is comparing integers, not strings.

          Qid is a structure containing path and vers fields:
          path is guaranteed to be unique among all path names cur-
          rently on the file server, and vers changes each time the
          file is modified.  The path is a long long (64 bits, vlong)
          and the vers is an unsigned long (32 bits, ulong).  Thus, if
          two files have the same type, dev, and qid they are the same
          file.
http://man.cat-v.org/plan_9/2/stat

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

#35
post #31

Oh god that code is fucking hideous. If someone who worked with me wrote that I'd talk to them about it and make sure they never did anything like that ever again. From the terrible argument names to the abuse of the single line if syntax (which should never be used anyway, always use curly braces.)

Thats hideous? I see worse code everyday.

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

#36
post #32

And what's the alternative for if(A && B){ x(); }else{ y(); }? Seems very easy to shoot yourself in the foot with this approach.

Well, you could

    if (one) {
    if (two)
    if (three)
    if (soon) {
        stuff
    }} else {
        else stuff
    }
Personally, I think I won't have any trouble reading that, but I have noticed I'm somewhat more tolerant than others in this regard. Though I am more OCD than others in other ways.

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

#37
post #31

Oh god that code is fucking hideous. If someone who worked with me wrote that I'd talk to them about it and make sure they never did anything like that ever again. From the terrible argument names to the abuse of the single line if syntax (which should never be used anyway, always use curly braces.)

You would love this:

https://feralbynight.googlecode.com/files/FeralbyNightv3_2_b...

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

#38
post #31

Oh god that code is fucking hideous. If someone who worked with me wrote that I'd talk to them about it and make sure they never did anything like that ever again. From the terrible argument names to the abuse of the single line if syntax (which should never be used anyway, always use curly braces.)

Thats hideous? I see worse code everyday.

Just because there's lots of worse code doesn't make that good.

There's worse songs than "Who Let the Dogs Out" but it's still a really bad song.

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

#39
post #31

Oh god that code is fucking hideous. If someone who worked with me wrote that I'd talk to them about it and make sure they never did anything like that ever again. From the terrible argument names to the abuse of the single line if syntax (which should never be used anyway, always use curly braces.)

Maybe it comes from using Python as my go-to language (and that it's my favorite language) but i personally like to avoid non-essential braces and other minutia.

Yes, of course, I know the argument: a one-line bracketless "if" can set-up a future developer for failure if they need to add an item to the conditional block. And if they for some reason decide not to read the actual conditional. And if they don't test it.

And I don't hate code that uses braces even when they're not strictly needed, but I personally prefer to omit them. And my feeling is that the dogma around braceless-ifs is a little overblown.

Of course when working on a team that has adopted a no-braceless-if policy, I conform. Having consistent code is way, way more important than somebodies own favorite bracing style.

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

#40
post #12

One downside to non-braced conditionals is that a semicolon accidentally placed after the conditional will cause the block to always run, e.g.: if (null != foo); bar(); This is valid code in C and Java, and bar() will always run in this case. Having seen people waste hours on such a semicolon, I always use braces, even in one-liners, because I never know when someone is going to break it out into multiple lines later…

I don't think braces solve that particular problem:

    if (null != foo);
    {
      bar();
    }
Post reply on HN