3 ms·
> Out of all the components of C, its time API is probably the one most plagued with legacy cruft. First off, no, locales and wide characters exist. This stat
by ajross 2y ago
> Out of all the components of C, its time API is probably the one most plagued with legacy cruft.
First off, no, locales and wide characters exist. This statement is just laughable.
But even as to time: that seems really unfair. This whole area is a footgun and has been the source of bad implementation after bad implementation, in basically every environment. But among those: The "struct tm" interface is notable for being:
1. Very early, arriving in C89 and the first drafts of POSIX, with working implementations back into the mid 80's.
2. Complete and correct, able to give correct calendar information for arbitrary named time zones in an extensible and maintainable way. LOTS of other attempts got stuff like this wrong.
3. Relatively easy to use, with a straightfoward struct and a linear epoch value, with conversion functions in each direction, and only a few footguns (the mix of 0- and 1-indexing was unfortunate). There are even a few quality of life additions like support for "short" month names, etc...
Really, these routines remain useful even today, especially since their use is guaranteed to integrate with your distro's time zone database which must be constantly updated to track legal changes.
There's stuff to complain about, but... no, I think the premise of the article is dead wrong.
- chrsig 2y agoi don't read that as a condemnation of usefulness of integrating w/ the system tzdb (every language stdlib does this under the hood) my biggest issue is that the structs and function definitions are pretty opaquely named and make it very hard to learn let alone teach newcomers.
- ajross 2y ago> 1. Very early, arriving in C89 and the first drafts of POSIX, with working implementations back into the mid 80's. I looked it up. In fact it's much earlier than that. The API arrived in time.h via v7 Unix in 1979. And it remains, unchanged, pervasively used, and most importantly still used for new code, four and a half decades later. Rather than "legacy cruft", this constitutes one of the most successful utility APIs in human history.
- ctoshiningc 2y agoI mean, this blog post is the kind of uneducated posturing that makes the JavaScript kiddies happy, because "crufty, old C is so bad, see!?". But none of them know enough to know that it's basically all bullshit.
- oliverkwebb 2y agoJavascript is a famously cruft free language, as we all know. My real question is how you created an account, found this article, presumably read through it, and wrote out multiple comments insulting me all within two minutes.
- Mikhail_Edoshin 2y agoC. J. Plauger wrote that some of C language developers were amateur astronomers so they understood time difficulties rather well.