News for hackers. Stuff that matters.
Re:My personal C coding style as of late 2023 by colejhudson on Sunday October 08, 2023 @11:09PM (#37816539)
I mean, being a bit glib here, but a lot of programming is dealing with someone else's type system.

Moreover, for those of us who write C fairly often, the mnemonics here are familiar.

Actually, as custom type systems go, this one is pretty elegant. Reminds me of Rust.

Re:My personal C coding style as of late 2023 by kristopolous on Monday October 09, 2023 @12:52AM (#37817025)
Speaking of type systems, I read glib as g-lib a few times and tried to understand how you were talking about the GNU lib in that sentence.
Re:My personal C coding style as of late 2023 by zombot on Monday October 09, 2023 @02:28AM (#37817528)
Wouldn't that have to be `glibc`?
Re:My personal C coding style as of late 2023 by slondr on Monday October 09, 2023 @03:08AM (#37817809)
Re:My personal C coding style as of late 2023 by zombot on Monday October 09, 2023 @07:41AM (#37819333)
I see. Thanks for that link!
Re:My personal C coding style as of late 2023 by wyldfire on Monday October 09, 2023 @03:47AM (#37818028)
It is unfortunate that the two have such similar names because there's a lot of room for confusion. It doesn't help that they have somewhat adjacent functionality almost.
Re:My personal C coding style as of late 2023 by userbinator on Monday October 09, 2023 @06:08AM (#37818780)
I did too. Humans use context to resolve ambiguities in language, and in this case the context was very much statistically favouring the library; if you're using it, glib is literally "someone else's type system".
Re:My personal C coding style as of late 2023 by oaiey on Monday October 09, 2023 @01:42AM (#37817224)
Yeah but not for basic types. Also, most code mingles sooner or later with other code. Than this is just ugly.
Re:My personal C coding style as of late 2023 by circuit10 on Monday October 09, 2023 @04:05AM (#37818122)
It’s better than dealing with needlessly long type names like uint32_t though
Re:My personal C coding style as of late 2023 by oaiey on Monday October 09, 2023 @08:36AM (#37819787)
No. It would be better if the standardization groups would have done that, but not when every developer has a different scheme
Re:My personal C coding style as of late 2023 by circuit10 on Monday October 09, 2023 @09:17AM (#37820173)
It’s not great but they’re just aliases so they’re interchangeable, which means you can keep everything consistent within a project and it won’t cause any problems when interacting with outside code
Re:My personal C coding style as of late 2023 by lelanthran on Monday October 09, 2023 @01:16PM (#37822715)
Until you include a header written by someone with the same opinion, and now you get compile errors because they both defined 'u8'.

I gotta be honest, all of those style suggestions look good until you try them in a non-solo and non-isolated project, and then you see what a mess you created.

We've all been there, as C programmers, and we've all done that in the past, which is why we don't do it anymore

Re:My personal C coding style as of late 2023 by circuit10 on Monday October 09, 2023 @05:15PM (#37825588)
Unless they were defined to completely different types, that shouldn’t be an error
Re:My personal C coding style as of late 2023 by lelanthran on Tuesday October 10, 2023 @01:36AM (#37828853)
> Unless they were defined to completely different types, that shouldn’t be an error

In this case it almost certainly will be - after all, the blog posts `byte` is defined as char, which could be signed or unsigned. A correct typedef for `byte` is `uint8_t`, so it's almost guaranteed that this will conflict.

Which is why I said it's best not to redefine the primitive types - you're almost certain to conflict with someone else who defined it differently.

Re:My personal C coding style as of late 2023 by uxp8u61q on Monday October 09, 2023 @08:52AM (#37819943)
Long type name?? uint32_t is literally 8 characters long. There's not much to cut here.
Re:My personal C coding style as of late 2023 by slikrick on Monday October 09, 2023 @09:30AM (#37820282)
if you like typing _, go ahead, but it's not 1 key press and shouldn't be treated as a keystroke like the letter a...
Re:My personal C coding style as of late 2023 by uxp8u61q on Monday October 09, 2023 @11:20AM (#37821354)
On my keyboard layout it's one keypress. And since code is read about 100 times as much it's written, I don't particularly care about reaching 250 WPM while writing code. The difficulty of writing code is thinking about it, not actually physically writing it.
Re:My personal C coding style as of late 2023 by circuit10 on Monday October 09, 2023 @11:24AM (#37821401)
Integer types are very common so it does still get a bit tedious. I guess it causes clutter when reading too
Re:My personal C coding style as of late 2023 by seanw444 on Monday October 09, 2023 @09:06AM (#37820072)
How about... u32?
Re:My personal C coding style as of late 2023 by slikrick on Monday October 09, 2023 @09:30AM (#37820287)
gasp blasphemy! C programmers literally can't have nice things
Re:My personal C coding style as of late 2023 by uxp8u61q on Monday October 09, 2023 @11:32AM (#37821476)
Sure, that's totally readable and meaningful.
Re:My personal C coding style as of late 2023 by oaiey on Tuesday October 10, 2023 @01:49PM (#37835167)
Unsigned 32 bit IEEE 754 floating point, right?
Re:My personal C coding style as of late 2023 by circuit10 on Monday October 09, 2023 @09:12AM (#37820125)
It’s longer than it needs to be when you’re typing it out so many times
Re:My personal C coding style as of late 2023 by billfruit on Monday October 09, 2023 @02:16PM (#37823403)
What are we trying to optimize, the number of characters to type or clarity/readbility?
Re:My personal C coding style as of late 2023 by circuit10 on Monday October 09, 2023 @05:16PM (#37825604)
Both I guess? I don’t think the extra length helps with readability at all
Re:My personal C coding style as of late 2023 by billfruit on Monday October 09, 2023 @02:15PM (#37823396)
uint32_t isn't that long, and is quite clear what type it means.
Re:My personal C coding style as of late 2023 by Sharlin on Monday October 09, 2023 @09:43AM (#37820387)
Rust made the correct choice: things used most often should be assigned the shortest names. This "Huffman encoding" style is what natural languages have evolved toward as well. In 2023, if I were to write C, and didn't have existing guidelines to adhere to, I'd most probably introduce the same typedefs as the author here has done.
Re:My personal C coding style as of late 2023 by kazinator on Monday October 09, 2023 @02:37PM (#37823656)
[delayed]