Hacker News new | ask | show | jobs
by User23 1083 days ago
I think ANSI C struct initialization is considerably more readable really. If there are enough members that it gets confusing then tab formatting the values along with a field name comment at the top works great. As for arrays, I don't see how designated initializers really offer anything interesting. Sparse array literals aren't really a pragmatically useful thing in my experience.

I'll allow of course that they don't "ruin the language" they just increase the cognitive burden of reading code.

1 comments

It's a substantial quality of life improvement to be able to express things like:

  vv = 3f_add(&v, &(3f_t){.x = .1, .y = .2, .z = .3 });
vs. having to declare and name the literal 3f_t beforehand, wasting my time and cluttering up the code with noise.
I actually was also thinking that way.

But then, after looking back at my old code, I struggled and crafted my 1SLOC guiding principle. I never looked back.

Wasting time when writing code is actually an investment into future read speed.

I even wrote some time ago about my rationale for 1SLOC https://blog.pwkf.org/2022/09/18/always-optimize-for-dummies...

I agree with the principle, but I don't agree that this is where it applies. Initializing things separately just makes it easier to make mistakes that are difficult to spot and harder for compiler to come up with meaningful warnings. It also doesn't make it immediately obvious to the reader that it's just a value to be passed as argument rather than further operated on.