ThePhD

Living disaster, ready to strike!

✨ Somehow Is A C Expert ✨ Smooches Unicode-kun 💕 Pixel Art is Cool 🎨 Banner by Bugurri and Avatar by KIING KIISMET


happy-iso
@happy-iso asked:

What do you like the most about C? It's a language I only ever learned for work cause I had to and haven't really engaged with in my off time - so to see someone who's as much of an expert in it as you are, I'm curious

I hate C with a burning passion, because it's not the language everyone kept hyping it up to be to me for the last ~15 years. I'm an expert because I want it to actually live up to that mantle, instead of there being a 100-page long footnote attached to every use of C for each specific platform/compiler/target.


You must log in to comment.

in reply to @ThePhD's post:

After BASIC and Pascal, while reading a first introductory text on C as a teenager, I immediately fell in love with the language. As such I find the above comment strange.

While no man-made thing will ever be perfect (e.g. header files werenʼt such a good idea after all; from a modern point of view a module-based system wouldʼve been better), I think that Dennis Ritchie nonetheless did a most excellent job in creating this language:

  • Especially compared to more modern alternatives, it is quite a small programming language—with C it is still possible to fit a complete description of its syntax on a single sheet of paper (try that with C++ or C#, for example)

  • Cʼs expressiveness is limited—while it will still take many years, it is possible to get to a point where one knows about every single knob and has essentially seen all the possible ways of combining the languages constructs. (Yes, thatʼs a boon in my book.)

  • With most languages, one is operating on top of a OS/libraries/software stack thatʼs quite deep; C, on the other hand, didnʼt used to be called “high level assembly language” for nothing—writing C programs feels much more like directly communicating with the system's hardware (especially on freestanding environments, when doing embedded development… but even on hosted environments, when writing PC software).

  • While modern optimizing compilers are sneaky little bastards, with some experience it is still possible to at least be able to take educated guesses as to which machine instructions a sequence of C code will get compiled down to. (What work will the machine have to do in order to process this or that Python sequence? Dunno.)

  • Mixing C and assembly language routines, even if it requires knowledge about the target platform, is quite easy. With niceties such as “name mangling” (of course done differently by different vendors), vtables and varying __thiscall calling conventions this is much more of a nuisance even in C++.

In short: I like—nay, love—the languages simplicity and its bare to the metal attitude. (Which also means, of course, that itʼs not the right tool for the job in all circumstances—I wouldnʼt use it for web development, for example… but thatʼs just common sense, I think.)

I hope the ISO working group will continue to resist the temptation to add feature upon feature to the language, thus avoiding the “death by feature creep” illness that plagues so many other languages (C# with its yearly release cycle comes to mind—with C# 12 even 1000+ page tomes have a hard time of really providing a full description of the language).

You can retain all of those properties and not have a long list of footnotes for key, foundational behavior. C is lacking in its control -- especially when it comes to structures -- and lacking in its ability to access hardware -- especially when it comes to specialized instructions -- than most other programming languages available right now. As a bandaid, most vendors provide "intrisics" headers or otherwise, but other languages besides C are offering better and more competitive/predictable access to hardware and other important bits.

I have no aspirations to see additional language-wide systems put into C. Most critical additions to C are, by nature, small and targeted with very few expections. But it's far from having met its potential in terms of being a small, efficient language for high-level assembly / predictable machine code instruction, and self-consistency with its own language feature ecosystem.

I guess what ticked me off in your original response was simply that you started it with “I hate C with a burning passion” (even if “to actually live up to that mantle” then softened this sentiment at the end).

I understand what youʼre getting at with this somewhat more detailed breakdown of the languageʼs problems (as you see them)… while I agree that a more uniform, standardized way of doing things across platforms would be nice—in that regard C23ʼs bit utility functions are a welcome addition—I think youʼre overstating the scope and impact of these problems.

Sure compiler-specific extensions, intrinsics and whatnot are sometimes a nuisance, but since most programmers usually spend their work days developing for a single platform/target of choice, I donʼt really see that as that much of a problem.

If I may I would like to pose another question:

Why did managed languages like Java (or C#) suddenly become all the rage at the beginning of this millenium? Was it really because of C++ʼs inadequacies/because constexprʼs, for-each loops, unique/shared_ptr were missing?

I donʼt think it was. Nor was it simply because “Garbage collectors are nice”. Rather, the “all-batteries-included” approach was what convinced people… and since then built-in dependency managers (like Cargo for Rust) have also become something that people just expect.

I would argue that Cʼs problem isnʼt the language… the main reason for its demise will be that it never even got a “standard library” that deserves to be called as such.

Sure, looking through the “WG 14 Document Log” thereʼs strb_t, which—if adopted by people—should help reduce string related bugs. However, even strb_t is just a thin veneer over null-terminated strings… it wonʼt really help with Uɴɪᴄᴏᴅᴇ strings, traversing and working with grapheme clusters, normalization forms and other niceties.

While there are some things that sound interesting—defer and _Optional/nullable types, for example—there are also proposals for “Case range expressions”, “Named loops” or “Strict order of expression evaluation” where I really question who these are for. (Are such minuscule things really of importance/deserving of a standards change?)

All that being said… before ending I would like to emphasize that the above sounds more negative than I intended it to be. I am grateful that people (like you) are spending their valuable time trying to improve the language. I just donʼt think that the kind of improvements that all to many seem to invest their time in will really save C from more modern alternatives like Rust and Zig.

"... Where I really question who these are for..."

Briefly ignoring that an industry professional decided to stop doing any number of other things they could do to join a National Body at ISO so they could participate in the C Standards Process and thus write things they think are worth fighting for (most of the time, anyways!),

For a paper like "Strict order of expression evaluation", is the kernel enough of a crowd to serve? https://lore.kernel.org/all/CAHk-=wid0xiN8a0=ixi3CyyZstcVnUqPXAMjethOxvXw1LjSuQ@mail.gmail.com/

More broadly, yes. There's going to be a lot of things that you don't care about / don't see the appeal of. To me, that's fine. But the additions to the language absolutely must serve a purpose, and we're adding them because C should be better. If I wanted to improve Zig or Rust or Odin or whatever, I would go help them out. It would probably be monumentally easier to contribute to those than have to write 5 papers and 4 Technical Specifications with wording just to get things sent in.