Hacker News new | ask | show | jobs
by nneonneo 937 days ago
The author is not wrong, the code really is crazy. Here's another random snippet from the ugly rewrite:

    for(char relative[] = "-2"; (relative[0] ^= '+' ^ '-') == '-' || ++relative[1] <= '9'; )
      gtk_list_store_insert_with_values(instances, NULL, -1, 0, relative, -1);
This is just pure excess cleverness. It's not even obvious how many times this loop runs for. There's a comment 1000 lines away that says this:

    #define NUM_INSTANCES 5 // or 3, but change char relative[] = "-2" to "-1"
This is just insanely unmaintainable code. If a string is warranted I would have just done the "stupid" thing with a `sprintf(buf, "%+d", relative);` to make it obviously correct, even if it seems "slower".
2 comments

I had to think about what that loop does for an embarrassingly long time.

I’ve never seen XOR used as an in-place alternation operator like that in a for loop. I’ve only ever seen it used as a swap function not an inline expression.

I’ve also never seen a for loop that uses a mutable string updated char-by-char like that.

It’s just… special.

This just got added to some lists of interview questions.