There are no "mods" on HN. There is one singular admin, dang, who pretty incredibly manages both the tech and the community.
In terms of people who have the power to downvote comments or flag stories, these are just regular HN users. There is a karma threshold at which downvote and flag links appear, but there is otherwise nothing special about this ability.
Some folks may think I'm splitting hairs, but I think it's important to clarify, as I often see comments blaming the "mods" for e.g. a post that was downvoted or flagged, as if the mods are some shadowy cabal (which can be the case when referring to Reddit mods). If posts are downvoted are flagged, it's because the community at large didn't like what you had to say.
I didn't see the original comment and I may take this better since it isn't my code but I don't ser this comment as negative.
If gives clear criticism which I can easily brush off as the way I want my library to work, but that when I read it I can agree with.
One if my major gripes with many libraries doing asynchronous work is that they just blindly assume I will be using their blessed event loop when in reality I already have an event loop. Which means I now need to put their code in a new thread, regenerate events and pass that to my event loop, that tends to add complexity.
.. but likely more than either of us get paid to comment.
bool is actually #define bool _Bool. You have to include <stdbool.h> to get it. That's ugly enough not to want to use it.
I'm looking at the April 2023 draft of ISO C. Under "Relational Expressions" I see that the result of an expression like x < y isn't bool, but ... int.
Here is the exact wording, minus a footnote reference:
Each of the operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false. The result has type int.
int is still the Boolean type in C, and null pointers and zeros are still falsy, relational expressions yield 0 or 1 of type int, and #define bool is just a sham for anal retentives.
> typedefs ending with _t are reserved for standards extensions
That is inaccurate. It's POSIX that reserves this namespace. Even if you're targeting POSIX, the reservation has next to no practical meaning, and can safely be ignored.
Here is why. What POSIX says is that when new type names will be introduced in the future in POSIX, they will have _t as a suffix. Well, so what? New type names in ISO C will also have _t suffixes, yet ISO C doesn't say anything about that being "reserved".
When a new identifier is introduced, it has to start and end in something.
Whenever POSIX introduces a new public identifier in the future, that identifier will either start with "a", or else with "b", or with "c" ... does that mean that we should stop using all identifiers in order not to tread on a reserved space?
When you have a language without namespaces/packages, you just live with the threat of a clash and deal with it when it happens.
Name clashes are not just with standards like ISO C and POSIX but vendor extensions and third-party code.
The mole is only a problem when it rears its head, and that's when you whack it.
Sure, which is why it got changed to a keyword in C23. I'll agree this should have happened earlier.
The return type of comparison operators is entirely irrelevant; you don't build APIs by reference to the return type of a comparison operator. It makes a difference to the reader whether your source code says "int" or "bool", that alone is all the reason anyone should need.
> That is inaccurate. It's POSIX that reserves this namespace.
You got me there. However, the question is, why would you add the _t? It serves no purpose. Typedefs have their own namespace anyway, you're not working around some possible collision by adding the _t.
That said I've already noted this is a commonly ignored aspect. I suppose it "feels" better/correct to some readers. I will happily agree this is the weakest point of my feedback either way, yet I still rather point it out and have people learn more details about this.
It is entirely relevant. The boolean type of the language is whatever is the type of (0 < 1).
> Typedefs have their own namespace anyway
Typedefs positively do not have their own namespace.
If you write
#undef getc
{
typedef char getc;
}
you cannot call the getc function in that scope; it is now the typedef.It is true that it's more correct to say "struct names have their own namespace", though I think we can infer what's actually meant here fairly easily.
That is false. If we declare an "enum foo", which is not a struct, then we cannot have a "struct foo" in that scope.
Alternatively, and especially in a library API, using bool is a clear specification of semantics.
An int parameter could have many meanings. An int return value similarly. In both cases, using "bool" makes the usage instantly more clear, without the need for comments, or man pages, or Doxygen, or super_long_parameter_names, or whatever.
I think it's useful.
You're providing a ton of code style feedback. That's fair, code style is important, I'm not saying you shouldn't. But surely when providing style feedback in public you could take a friendlier tone :(
Thanks!
There are plenty of constrained environments where this is indeed a feature to advertise, namely older machines and embedded systems.
Anything from the 80s/90s isn't really worth supporting. We gotta draw the line somewhere.
It matters because the return value sense is different; an "int" return for a status-ish thing in a modern library generally means 0 for success, nonzero for error codes. "bool" is the other way around, 0 for failure-y. In this case it's a status retrieval function so it's pretty clear that it's intended as a boolean but it'd still be better to actually make it bool.
Integer promotion should go, like implicit cast for anything except void* and literals, but we are missing a dynamic/static casts syntax explicit split. Only one loop keyword, loop {}, no switch, no anonymous block, no "a?b:c" operator. typedef has to go, (and typeof,generic,etc), the variable arguments of preprocessor function should be defined once and for all. __thread must go as tls should be managed dynamically and explicitely with the system interface, never statically and hidden by the runtime. Only sized primitive types (u8/s8...). That said, anonymous union/struct are very nice for complex memory layout.
And all the things I am forgetting right now.
With the pre-processor and coding discipline you can get close to that already, but I was told that what I am describing is basically the simplicity of rust syntax, true? Namely it is easier to write a naive rust compiler than a C compiler?
This operator is very useful and uncontroversial in Perl, it's normal (and quite readable) in selecting a value for assignment. One is expected to use good practices with it, but it is nice.
Is the problem the fact that in C you can use it instead of if, selecting not values but actions, like (a > b) ? printf("A") : printf("B");
I have also seen them used cleanly and beautifully, but that is a rare occurrence.
For instance, a "feature" of significant and pertinent impact missing, in the list I provided, load and store from unaligned memory address should have their own keywords as this is really important, even though modern hardware micro-archs tolerate that at a cost. Anybody using that abomination of "struct packing" C extensions should think again: C has been meant for aligned access by default, namely unaligned access should be at a syntax cost, and should pop up from the syntax and be HARDCORE explicit. I don't even think rust syntax is that clean, am I wrong? (hopefully)
For instance in linux printf, I did run in a beautiful (irony) "aligned" attribute on a stack variable. I was reading the code and I though there was a bug since I did not read the variable declaration as I was very mistaken that the variable name was enough... Yeah, should be banned from the kernel (hopefully, rust is careful to avoid that abomination in its syntax).
When I have "packed" data structures, I am, usually, careful at having everything "byte" defined and use explicit macros for Xword loads and stores.
"Letting the compiler do that for you" is dual edge sword. And I don't even start on the _Generic abomination, which creates so much type indirection you don't know what you are dealing with unless you read a ton more code.
const value = cond ? a : b;
Using an if instead would mean you can't make it const, and is usually more convoluted to read.For pretty much all other use cases, I agree that ifs are better.
For example, the following F# code (you can run `dotnet fsi` in a terminal to try it out, if you have dotnet installed) is equivalent to a ternary expression:
// the value of x is "is_not_lower" after evaluation (x is a constant/immutable value, just like a 'const' value in JS) let x = if 0 > 1 then "is_lower" else "is_not_lower"
Which is equivalent to the following (in JS): const x = 0 > 1 ? "is_lower" : "is_not_lower"
In F# (and also Kotlin which I linked before), you can have clean code with if-elif-else ladders while the equivalent (using nested ternaries) would be hard to read. For example:
// the constant/immutable variable "comparison" is either "HIGHER", "LOWER" or "EQUAL" depending on the branch taken let comparison = if a > b then "HIGHER" elif a < b then "LOWER" else "EQUAL"
In JS land (and also most common programming languages which have plain if-statements), I agree a ternary would often be preferrable as long as it's not nested.
a = if x then y else z
is just a more verbose version of a = x ? y : z;
Raku uses yet another form of the same operator: a = x ?? y :: z;
Syntactic sugar :-) a = x ?? y !! z
And that's because a single : is used for many other semantics in the Raku Programming Language. And ?? and !! standout better in code.I think I made this mistake because :: was used in one of the drafts for Perl 6, but the final specification uses !!
a = (x < 5 ) ? 'LESS'
: (x > 5 ) ? 'MORE'
: 'SAME';You must be joking.
You know the answer?
It's become such a common practice to suffix your typedefs with _t it's practically a de facto standard at this point.
Since everyone's already namespacing types with some kind of prefix, I don't see the problem nor have I ever experienced a negative consequence after decades of writing C this way.
Oh come on, let's not play the language police... You are entitled to your language likings, others are not. C89 is simple, straightforward, no bells and whistles, and some people like that (I do).
> There's nonstandard nomenclature in "_dispose"; if the constructing function is called _create, the common pattern is to pair it with _destroy.
"Nonstandard" says who?
In my 20 years of C I've seen all possible combinations of _init/_create/_new/_alloc _free/_deinit/_release/_delete/_destroy/_dispose. As long as it's consistent across the codebase, it's fine.
> typedefs ending with _t are reserved for standards extensions, though these days people ignore this a lot because it feels like general practice to add _t.
Not really. The usual convention for _t is to differentiate between raw struct names and typedef structs, such that you know whether you have to prefix "struct" during declaration. i.e. `struct foo {}`/`typedef struct {} foo_t`
> Both _select functions fall short in that they do not allow select'ing on channels + other file descriptors simultaneously.
Good point
First, a commit to change the docs to say it's a pure C99 (or C11 or C17) implementation.
Second, for each of your points, a single commit fixing each style issue (_dispose -> _destroy, typedefs).
Seperately, another MR with the commit for _select improvements.
Or maybe just send the C99 one first, and if that gets rejected, don't bother with the rest.
Going for C89 for a truly portable project is probably fine.
and by a dedicated few to this day: https://lists.gnu.org/archive/html/tinycc-devel/
It's not much but it's not dead.
How generous. The comment reminds me of this passage in C. Northcote Parkinson's famous 1957 book:
"The man who is denied the opportunity of taking decisions of importance begins to regard as important the decisions he is allowed to take. He becomes fussy about filing, keen on seeing that pencils are sharpened, eager to ensure that the windows are open (or shut), and apt to use two or three different-colored inks."
How can it be that in HN a comment like this, which is all about trivialities and the personal sensitivities of the commentator, and which contributes nothing relevant to the matter at hand, receives the most upvotes? Is this comment somehow pinned to the top instead?
Many here seem just disparaging about Reddit, but if you want to see an actually useful and intelligent comment from someone who actually knows something about the subject, take a look here: https://old.reddit.com/r/C_Programming/comments/18fzr1a/a_pu.... I'd expect at least that level from comments on HN.
I feel like purposely emphasizing C89 in your project name is meant to highlight some sort of greybeard or serious hacker aspect to it. Presumably the poster was thinking along the lines of "if you're trying to show how proficient you are with a sharp knife, here's a list of all the ways you cut yourself with it."
It's unfortunate that you pose this as a rhetorical question, it has an actual answer: replace "pure C89" with "C89 compatible", wrap it in braces, and move it to the end of the title.
The message you're communicating by putting "pure C89" right front is very different from having a "(C89 compatible)" at the end: the former sounds like C89 is somehow an unequivocally good thing ("pure") while the latter makes clear that it is to address an unfortunate reality of engineering life. It would also distance you from C style and quality focused comments.
> which is all about trivialities and the personal sensitivities of the commentator, and which contributes nothing relevant to the matter at hand
The select API concern seems relevant and actionable.
Not even English has the "purity" that you subliminally presuppose in your (entirely unnecessary) assertions. See e.g. https://www.merriam-webster.com/dictionary/pure?utm_campaign.... And not a single one of your arguments had to do with "language purity"; instead you nit-picked about naming and features you miss; so what? But hey, it's open source: impress the world with your own version of the library.
I didn't consider the aspect of which modern toolchains are still attached to C89, but using a language spec that's 35 years old has some relationship to the grayness of one's beard. But in any case I used the term greybeard to evoke the aesthetic of "fuck modernity, embrace terse C, suckless software" etc.
Or indicating that it will work if you want to fold the code into a C89 project, which is not exactly a rare concern.
Even if you think they wasted their time, they didn't waste your time, and I value the existence of things like this, which means even if you don't, at least some others do.
The more reasonable discussion then becomes: fix the non C89 issues so the statement becomes accurate, disclose that it uses extensions, or as some have constructively suggested consider just targeting C99 rather than GNU89. Not sure why you think criticism of something not being what it claims is inappropriate.
They're mostly legitimate, good-quality feedback for a new C library.
_create/_destroy -- yes; custom allocator, logger, debug level setting -- yes; returning a file descriptor -- yes; the implied suggestion to move stuff out of the header -- yes.
This is important feedback. These things will require a breaking change down the line unless you tackle them before 1.0.
I encourage the author to take this onboard: it'll make your own life easier and your library a better C citizen.
There's nonstandard nomenclature in "_dispose"; if the constructing function is called _create, the common pattern is to pair it with _destroy.
typedefs ending with _t are reserved for standards extensions, though these days people ignore this a lot because it feels like general practice to add _t.
There's no way to pass in a custom allocator, or logging callback, or set some debug logging flags. Maybe something to tackle later.
Both _select functions fall short in that they do not allow select'ing on channels + other file descriptors simultaneously. General library design practice is to have the library return a file descriptor that can be used in whatever event loop the application already uses. (The fd can be a dummy pipe or eventfd.)
All of these things are in the header, so they matter the most as they set ABI and API for any user. Unfortunately getting them right as early as possible is important to avoid breaks; yet very hard to do since often API aspects only become clear after a library has non-trivial users.
[edited to tone down a bit]