News for hackers. Stuff that matters.
Re:Switching to C over 'Modern' Programming Languages by hnarn on Thursday April 13, 2023 @03:05AM (#35552055)
Is this becoming a thing now (or maybe it was always a thing), where a language, like Rust, has become popular enough that instead of everyone talking about learning it, they now want to talk about how “simple” and “beautiful” C is for no other reason than signaling how different you are from the zeitgeist?

Rust exists for a reason, and it solves specific problems. That’s the “magic”, just like any abstraction in any language. So what’s the argument, that abstractions are bad? Clearly not:

> I also haven’t really experienced the problems Rust claims to be solving

This is like hearing someone say 20 years ago that “I’ve heard a lot of good things about PHP but I don’t see the point of it, because I’ve never had to write a web application that interfaces with a database” — well, no shit?

Re:Switching to C over 'Modern' Programming Languages by ChrisRR on Thursday April 13, 2023 @03:38AM (#35552242)
I'm a C programmer by day and I disagree with them, C is only simple if you're trying to do simple tasks with it.

The very common thing I want to use in C is some sort of variable size string object. But no, I have to dynamically allocate a buffer that I know will be at least the right size for any text I ever put into it, or do I create a buffer that's the correct size for that string but re-alloc if I ever change it to a longer string. But then how do I store the buffer size? Do I want to create a struct that constains a point to the buffer and the length, or use sizeof() to calculate the string length? But then I can't use sizeof() if I pass that buffer into a function via a pointer. If I pass that string to a function is it being copied straight away or just storing the pointer so I can't change the string at a later date. I can't enforce copy semantics

And god forbid you ever forget to include space for the NULL

I just want a string I can dump some text in, I don't want to go searching for libraries, I don't want to have to consider allocation and copying and all that crap. If I wrote half of my boilerplate C code in python it would look just as simple and beautiful (if not more)

Re:Switching to C over 'Modern' Programming Languages by ChuckNorris89 on Thursday April 13, 2023 @03:40AM (#35552256)
>I'm a C programmer by day and I disagree with them, C is only simple if you're trying to do simple tasks with it.

C gives you enough rope to shoot yourself in the foot. And rightfully so. It's meant not to hold you back from doing voodoo with low-level stuff. It came out in a time when everyone was coding assembly.

Re:Switching to C over 'Modern' Programming Languages by flohofwoe on Thursday April 13, 2023 @04:19AM (#35552502)
> when everyone was coding assembly..

This was before my time, but I think it's a common misconception (only true for operating system development). When C was created, there was already Lisp, Cobol, Fortran, Algol, Simula, BASIC... and SmallTalk and Prolog were just around the corner - and most of those are much higher level than C).

Re:Switching to C over 'Modern' Programming Languages by uranusjr on Thursday April 13, 2023 @04:53AM (#35552734)
I think parent knows. A more accurate description would be everyone of the intended audience was writing assembly. Yes there are other languages of higher levels, but C was not invented to help their users. And since they are also not really what Rust targets either, IMO it’s reasonable to shorten it to drop the qualifier in this context.
Re:Switching to C over 'Modern' Programming Languages by tourmalinetaco on Thursday April 13, 2023 @08:36AM (#35554439)
> since they are also not really what Rust targets either

Exactly this. This belief that Rust can and even will replace C is at best ignorant and at worst evangelical. In fact I’m convinced most Rust enthusiasts on HN are less involved in programming and more with politics.

While I’m all for mem-safe languages Rust is simply too abstract and undefined to work on any real embedded systems work. At most, it can work on the driver level, but even that code will need to be constantly redone as the language ages without any proper specifications.

Re:Switching to C over 'Modern' Programming Languages by pjmlp on Thursday April 13, 2023 @03:31PM (#35560931)
C was invented in the context of porting UNIX, while the world outside Bell Labs used something else, that is all there is to it.
Re:Switching to C over 'Modern' Programming Languages by jacquesm on Thursday April 13, 2023 @04:53AM (#35552739)
Sure, but none of those were for systems programming which is squarely the domain that C was aimed at, case in point: the first thing that C was used to write was UNIX (before then it was BCPL and this was iirc before C even had structs which made that a very tricky job, once structs were in place it got a lot easier). Probably Don Hopkins has more knowledge about this.
Re:Switching to C over 'Modern' Programming Languages by flohofwoe on Thursday April 13, 2023 @05:07AM (#35552847)
> before C even had structs which made that a very tricky job...

...interesting that you mention that, I think that functions and structs are the essential 'core abstraction tools' that get you to at least 80% of any higher level abstractions that were invented since then, and this is exactly the reason why C is still quite popular. Its feature set is just enough to be considered a high level language which enables abstractions, but not more (especially no fads and fashions that came and disappeared again).

Re:Switching to C over 'Modern' Programming Languages by pjmlp on Friday April 14, 2023 @04:58AM (#35567159)
C23 has lots of stuff into it, except improved safety.
Re:Switching to C over 'Modern' Programming Languages by pjmlp on Thursday April 13, 2023 @03:09PM (#35560558)
There were enough languages for systems programming outside Bell Labs, all the way back to 1958.

It is a urban myth that C was the first one, usually pushed by naturally UNIX folks.

JOVIAL, ESPOL, NEWP, PL/I, PL/S, PL.8, PL/M, Bliss, Mesa, Modula-2, VMS Basic, VMS Pascal,...

Re:Switching to C over 'Modern' Programming Languages by jacquesm on Thursday April 13, 2023 @04:54AM (#35552746)
> C gives you enough rope to shoot yourself in the foot.

If this was intended to illustrate the unexpected consequences of undefined behavior it succeeded remarkably well!

Re:Switching to C over 'Modern' Programming Languages by flohofwoe on Thursday April 13, 2023 @05:11AM (#35552885)
Undefined Behaviour was a very late 'addition' to C, it only became necessary when C was standardised around 1990. And only after two more decades passed, UB became an actual problem when compiler vendors decided that it's fine to exploit it for optimization tricks.
Re:Switching to C over 'Modern' Programming Languages by Brian_K_White on Thursday April 13, 2023 @07:43AM (#35553949)
Did you miss their point? They merely used UB, correctly, as a term we all do recognize today.

I will utterly kill all humor by explaining it:

They made a funny observation about a thing that happens. The thing that happens is (today) called UB. The funny observation is that that comment kind of exhibited the outward appearance of what the effects of UB could look like.

It began reciting one metaphore, "enough rope to hang yourself" but mid-way unexpectedly switched to a different metaphore "shoot yourself in the foot", producing a combined invalid nonsensical output. As though a program suffered some UB in the routine for looking up and printing metaphores.

The comment author might have done it on purpose. Maybe they intended to make exactly that joke.

The history of the term UB has no more bearing than the history of any of the other words used.

Re:Switching to C over 'Modern' Programming Languages by Panzer04 on Thursday April 13, 2023 @10:15AM (#35555791)
“Decided that it’s fine to exploit it for optimisation tricks” is a poor characterisation. The reality is, if you define particular behaviours you will harm performance in some cases. If you define how something in particular should happen, then all architectures will need to implement that, regardless of their underlying semantics.

eg. C leaves the case of exceeding the size of an int undefined. In most cases it has a predictable effect on modern, mostly similar architectures but that is by no means guaranteed, and forcing an architecture to calculate overflow a particular way seems like a negative.

That being said, everyone has a pet example of a compiler doing some really odd and deep optimisations - I suspect that’s mostly due to successive layers and optimisers adding up to have unexpected effects, rather than a deliberate effort by compiler writers - but I’m no expert on the matter.

Re:Switching to C over 'Modern' Programming Languages by SAI_Peregrinus on Thursday April 13, 2023 @03:33PM (#35560961)
> UB became an actual problem when compiler vendors decided that it's fine to exploit it for optimization tricks.

Section 4. Conformance says "A strictly conforming program shall only use those features of the language and library specified in this International Standard. It shall not produce output dependent on any unspecified, undefined, or implementation-defined behavior, and shall not exceed any implementation limit."

Compilers are not allowed to produce output dependent on UB for strictly conforming ISO C programs, they must optimize those statements out. Treating UB as impossible is required for ISO C. It's NOT required for GNU C, or Clang C, or Microsoft Visual C, but they usually do so anyway (even though they're not compiling strictly conforming ISO C programs).

Re:Switching to C over 'Modern' Programming Languages by coldtea on Thursday April 13, 2023 @04:56AM (#35552763)
>It came out in a time when everyone was coding assembly

Expect to hear from @pjmlp on this!

Re:Switching to C over 'Modern' Programming Languages by krinkatt on Thursday April 13, 2023 @04:26AM (#35552544)
I have something like this that serves me well:

  struct strbuf { size_t cap, len; char *str; };
  void sb_setf(struct allocator *a, struct strbuf *sb, const char *fmt, ...);
  void sb_appendf(struct allocator *a, struct strbuf *sb, const char *fmt, ...);
  // have other convenience functions for formatting fixed point values like "prefix AAA.BBB suffix" ("voltage: 7.23 V")
  // special helpers for dates, times, etc.
Just keep building that library up and you'll have growable buffer, strings, lists, hashmap (uintptr -> uintptr is all you need in 99% of cases I've found, maybe some helper functions for string key -> void * built ontop of uintptr->uintptr) + replace/rewrite the standard library to operate on these types instead and you're good to go.
Re:Switching to C over 'Modern' Programming Languages by Someone on Thursday April 13, 2023 @04:52AM (#35552731)
That works until you want to use code from somebody else who also has something like that that serves them well, but is slightly different.

If you’re extremely lucky, things will compile and work.

If you’re just lucky things won’t compile, and you’ll have to write conversion functions (or macros).

If you’re unlucky, there will be subtle differences, likely poorly documented, between the libraries, and code will compile but have subtle bugs.

Of course, other languages have that problem, too, but at the higher level of json parsers or graphics libraries, not at the basic level of strings, lists, or maps.

Re:Switching to C over 'Modern' Programming Languages by coldtea on Thursday April 13, 2023 @04:55AM (#35552751)
Could even use something like Gnome's GLib
Re:Switching to C over 'Modern' Programming Languages by coldtea on Thursday April 13, 2023 @04:53AM (#35552737)
>The very common thing I want to use in C is some sort of variable size string object. But no, I have to dynamically allocate a buffer that I know will be at least the right size for any text I ever put into it, or do I create a buffer that's the correct size for that string but re-alloc if I ever change it to a longer string. But then how do I store the buffer size?

As a C programmer shouldn't you have a library abstracting all this by now? Either your own or one of the dozens available, including pascal-style strings?

Re:Switching to C over 'Modern' Programming Languages by jacquesm on Thursday April 13, 2023 @04:57AM (#35552770)
It's funny how both C and LISP programmers seem to suffer from NIH to the point that they'll roll their own just for the heck of it rather than to first see if there is a library that they can use.

The long term cost of those decisions as well as the number of really bad bugs (and security issues) that can be traced back to one-off code is likely much larger than the same figure for well used libraries. But it all sort of evens out whenever a bug in such a library is found because then it is so widespread that lots of systems will suffer.

Weird how that works.

Re:Switching to C over 'Modern' Programming Languages by coldtea on Thursday April 13, 2023 @05:16AM (#35552920)
>It's funny how both C and LISP programmers seem to suffer from NIH to the point that they'll roll their own just for the heck of it rather than to first see if there is a library that they can use.

Well, not sure about the LISP programmers, but C programmers have a good reason: they work under different environments (from embedded to Windows, legacy UNIX, the latest Ubuntu, ...) and also have different needs, regarding allocation, string management, etc. So one-size-fits-all lib might not cut it for everybody. It can also be as simple as having an inherited codebase which uses something else.

Still, there are popular string libraries, and C programmers do use them when they can.

Re:Switching to C over 'Modern' Programming Languages by kaba0 on Thursday April 13, 2023 @05:27AM (#35552999)
What exactly is a problem with C++’s strings, or especially Rust’s? Everything you mentioned can be controlled as explicitly as you want.

The only problem is C is simply not expressive enough to have proper abstractions like that.

Re:Switching to C over 'Modern' Programming Languages by coldtea on Thursday April 13, 2023 @06:35AM (#35553429)
>What exactly is a problem with C++’s strings, or especially Rust’s? Everything you mentioned can be controlled as explicitly as you want.

Everything else, however, cannot.

Re:Switching to C over 'Modern' Programming Languages by kaba0 on Thursday April 13, 2023 @06:50AM (#35553537)
Like what? C++ and Rust can do everything C can.
Re:Switching to C over 'Modern' Programming Languages by tourmalinetaco on Thursday April 13, 2023 @08:17AM (#35554266)
They literally cannot. For one, neither C++ or Rust conform to standard C, meaning they already deviate from what C does on a basic level.

Their industry uses are highly different as well. C is almost a requirement for embedded systems, and while C++/Rust can be used there, they’re simply too complex and in Rust’s case additionally too young to be adopted. C++, and possibly Rust (if it can get its act together), are more used in high level programming, as that’s what they’re built for.

If C++ could do what C can, then why is the Linux kernel 98.5% C code? Wouldn’t it be better to use a more varied and powerful language?

Or, maybe different languages have different use cases and cannot be directly slotted in to replace one another.

Re:Switching to C over 'Modern' Programming Languages by tialaramex on Thursday April 13, 2023 @09:03AM (#35554777)
Linux isn't written in standard C. Not only does it not accept C's aliasing rules (hence the kernel is compiled with them disabled, which the standard doesn't offer), it doesn't even accept the memory model, because it had its own memory model first and it likes that one better.

As a result to some extent GCC and Clang are also compilers for some sort of "Linux C" which is strongly reminiscent of the ISO standard language but distinct.

And there's no reason you would choose C++ for a project where you'd otherwise use C on account of the (exaggerated) relationship between the two languages, the reason you'd do it would be that you want C++ features, and Linus doesn't want C++ features. Projects to "just" compile the existing Linux code but with C++ compilers failed AFAIK.

Re:Switching to C over 'Modern' Programming Languages by shrimp_emoji on Thursday April 13, 2023 @09:57AM (#35555537)
Re:Switching to C over 'Modern' Programming Languages by flohofwoe on Friday April 14, 2023 @03:36AM (#35566601)
Unions for type punning is actually entirely valid in C, it's only UB in C++.

(I agree though that the C standard isn't actually relevant in the real world, most C compilers treat it more or less as a 'suggestion', unless enforced with options like '-pedantic')

Re:Switching to C over 'Modern' Programming Languages by kaba0 on Thursday April 13, 2023 @09:11AM (#35554883)
So your answer is “because they are not C”…?

What does language complexity has to do with anything? It will get compiled down to machine code, and both can be and are used for embedded. They occupy the exact same low-level niche as C, hell, they may be even more level as they can also do things like SIMD.

Linux kernel is C because Linus doesn’t like C++, it’s that easy. And usually no, why would you use multiple languages in a project if you don’t have a good reason?

Re:Switching to C over 'Modern' Programming Languages by cozzyd on Thursday April 13, 2023 @09:55AM (#35555509)
It is quite difficult to write idiomatic C++ without memory allocation, for one, which is often a requirement for embedded code or any high-availability code that is not allowed to have memory fragmentation.

Sure, it's possible (you can write C in C++, for the most part, and to its credit, C++ has placement new). But many of C++'s niceties require memory allocation, making much of its value-add over C questionable.

Re:Switching to C over 'Modern' Programming Languages by pjmlp on Thursday April 13, 2023 @03:30PM (#35560914)
It super easy, we did it all the time back in the MS-DOS days.
Re:Switching to C over 'Modern' Programming Languages by cozzyd on Thursday April 13, 2023 @05:30PM (#35562328)
right, but that was pre C++ niceties like the STL :).
Re:Switching to C over 'Modern' Programming Languages by pjmlp on Friday April 14, 2023 @02:20AM (#35566133)
C++ compilers shipped their own collections, for Borland compilers it was BIDS.

The first version used preprocessor macro tricks for generatic code, basically what Go folks re-discovered with //go:generate, we already had it in 1992.

BIDS 2.0 already used templates.

It was exactly because even C++ for MS-DOS provided safer library than C, that I was never that into C. It wasn't better than TP in features and safety, only in portability, and that I could get from C++ anyway.

Re:Switching to C over 'Modern' Programming Languages by cozzyd on Friday April 14, 2023 @11:52AM (#35570926)
That's fair! Perhaps I should amend to say that "current" idiomatic (almost got autocorrected to idiotic on my phone) c++ code is allocation heavy. Probably there exist suitable libraries I don't know about that basically implement the STL using predefined arenas for storage.
Re:Switching to C over 'Modern' Programming Languages by scoutt on Thursday April 13, 2023 @09:43AM (#35555318)
Last time I checked "Formatting is Unreasonably Expensive for Embedded Rust" (1)

And/or you need a crate like alloc, heapless, etc.

For the sake of a sprintf "abstraction"...

(1) https://jamesmunns.com/blog/fmt-unreasonably-expensive/

Re:Switching to C over 'Modern' Programming Languages by orf on Friday April 14, 2023 @02:25PM (#35572967)
It’s not really a sprintf abstraction.
Re:Switching to C over 'Modern' Programming Languages by kjs3 on Thursday April 13, 2023 @10:07AM (#35555666)
If all you do is write code on Linux/Windows/MacOS, C++ strings might be fine. Things are different in the wider world. Many places I use C don't even have a C++ compiler (embedded, in particular).
Re:Switching to C over 'Modern' Programming Languages by flohofwoe on Friday April 14, 2023 @03:29AM (#35566554)
I don't even know where to start with C++ stdlib string problems, but being mutable and doing a unique heap allocation (above a certain length) are definitely at the top of the list.

std::string_view would have been a good thing if it hadn't added another memory corruption foot gun.

A general string type is one of those things where you can either have convenience or performance, but never both.

Re:Switching to C over 'Modern' Programming Languages by pjmlp on Friday April 14, 2023 @04:56AM (#35567139)
They are still better than str...() and mem...() all over the place, and all relevant C++ compilers have options to turn bounds checking on.
Re:Switching to C over 'Modern' Programming Languages by flashgordon on Thursday April 13, 2023 @11:41AM (#35557159)
My c knowledge is obviously old. I wonder if the author is lamenting the lack of a "modern" string manipulation in the standard library beyond just working on char buffers?
Re:Switching to C over 'Modern' Programming Languages by xigoi on Thursday April 13, 2023 @03:59PM (#35561306)
Okay, so you write your own string library. Now you'd like to do the same thing for resizable arrays, so you write a resizable array li… oops, you can't, because C doesn't have parametric types.
Re:Switching to C over 'Modern' Programming Languages by flohofwoe on Friday April 14, 2023 @03:13AM (#35566454)
Preprocessor macros are an entirely valid tool in the C language toolbox, even if demonized by C++ coders.
Re:Switching to C over 'Modern' Programming Languages by pjmlp on Friday April 14, 2023 @04:54AM (#35567129)
Even Macro Assemblers from the MS-DOS and Amiga days are better than C pre-processor macros.
Re:Switching to C over 'Modern' Programming Languages by melagonster on Friday April 14, 2023 @02:06PM (#35572679)
it is black magic, absolutely respect C developers.
Re:Switching to C over 'Modern' Programming Languages by flohofwoe on Saturday April 15, 2023 @05:58AM (#35579127)
But the preprocessor is just simple text replacement, nothing magic about it.
Re:Switching to C over 'Modern' Programming Languages by tpoacher on Friday April 14, 2023 @04:42PM (#35574466)
He didn't say "write your own library". He said "use" one (your own if you prefer). Or are you going to suggest there are no good string handling libraries for C?
Re:Switching to C over 'Modern' Programming Languages by xigoi on Friday April 14, 2023 @06:44PM (#35575822)
It doesn't matter. My point is that it's not possible, not for you and not for anyone else, to implement a type-safe generic resizable array library in C.
Re:Switching to C over 'Modern' Programming Languages by tpoacher on Friday April 14, 2023 @06:35PM (#35575719)
> But then I can't use sizeof() if I pass that buffer into a function via a pointer.

Obviously, this isn't necessarily an improvement, but in theory you could do this:

  size_t getlength( int m, char (*p) [m] ) { return sizeof *p; }
where you'd be calling it like this:

  char mystring[] = "Hello";
  getlength( sizeof mystring, &mystring )
But then you're back in "having to pass the length as a separate parameter" territory, I guess. (but at least it's the length of the array here, not just the zero-terminated component, which is what you wanted).
Re:Switching to C over 'Modern' Programming Languages by flohofwoe on Thursday April 13, 2023 @03:34AM (#35552220)
I'm a programmer since the early 90's, but I have seen this problem only ever with Rust so far (where people are eager to learn something new, pick Rust, and then quickly get jaded - case in point, that's also me - I learned enough Rust to write a home computer emulator but in the process realised that it is not the right language for me, even though it should be from its feature set).

It feels a bit like a speed run of C++, at least this took around 2 decades for people to get fed up and turn away ;)

(and interestingly, I also switched back to 'mostly C' for my hobby stuff, and I'm quite happy with it)

Re:Switching to C over 'Modern' Programming Languages by camgunz on Thursday April 13, 2023 @06:31AM (#35553396)
> It feels a bit like a speed run of C++

I've felt that way too, and it's been enough to push me away even as I've tried to build things in Rust in earnest. Along the same lines, I've found it hard to say exactly why I like C and super dislike C++. I guess I have to say it's simplicity--like I won't argue C is by itself simple (integer promotion by itself is not simple) but it's definitely simpler than C++, and the simplicity and power of its core conceit (everything is a number) is just enrapturing. I think it's just an ethos thing: Rust doesn't strive to be simple and I find that makes it impossible for it to delight me.

I also think that's broadly why newer languages have failed to capture the je ne sais quoi of C: you really can't get away with "everything is a number" these days.

Re:Switching to C over 'Modern' Programming Languages by oconnor663 on Thursday April 13, 2023 @02:46PM (#35560190)
> everything is a number

I don't think C consistently lives up to this principle:

- In the memory model, even simple integers can hold "poison" values.

- Pointers usually behave like integer addresses, but in the memory model they have "provenance" (edit: spelling), and they also have to follow "strict aliasing" rules.

- Signed integer overflow is UB. We could ignore integer promotion rules most of the time, if not for this restriction.

- Even simple integer assignment isn't simple when an integer is shared between threads. Atomic orderings are hilariously complicated.

I worry that a lot of people who find delight in C just...aren't aware of these rules? Or maybe aren't consistently aware? Or maybe are aware but think that some violations are benign?

Re:Switching to C over 'Modern' Programming Languages by agalunar on Thursday April 13, 2023 @02:57PM (#35560379)
Small typo correction for anyone trying to search or learn more about the term: it's "provenance", not "providence".
Re:Switching to C over 'Modern' Programming Languages by oconnor663 on Thursday April 13, 2023 @02:59PM (#35560396)
Ha woops. My mind is in Rhode Island :)
Re:Switching to C over 'Modern' Programming Languages by agalunar on Thursday April 13, 2023 @06:25PM (#35562961)
^_^

Although I am tickled by the idea of pointer providence – that pointers are handed to us from on high, from the C gods.

Re:Switching to C over 'Modern' Programming Languages by cozzyd on Thursday April 13, 2023 @08:13PM (#35563938)
That's how it works in Python
Re:Switching to C over 'Modern' Programming Languages by flohofwoe on Friday April 14, 2023 @03:05AM (#35566409)
We're very aware and try to shield ourselves somewhat with compiler options (eg. max warning level already goes a long way), sanitizers and analyzers (thankfully availability of such tools has improved dramatically with clang's ASAN, UBSAN, TSAN and the clang static analyzer).

(and actually: yes, some rules are benign if the major compilers agree on the same non-standard behaviour, so far I have never seen unions used for type punning break in C++ for instance - it's good that C++ now offers a 'proper' alternative though).

It's pretty much an illusion that any non-trivial C or C++ program can be entirely standard compliant, it always depends on the specific compilers it has been tested with - which is still a better situation than Rust, which only has a single implementation (so far).

Re:Switching to C over 'Modern' Programming Languages by camgunz on Friday April 14, 2023 @02:02PM (#35572624)
Yeah it is bonkers to me that people don't turn all the stuff on. There's a lot of help out there that is basically free. It's worth taking an hour or so to go through all the checks--if nothing else it'll probably make you wise to some new footguns.
Re:Switching to C over 'Modern' Programming Languages by camgunz on Friday April 14, 2023 @01:57PM (#35572552)
Oh that's what I was nodding at with my "I wouldn't call C a simple language" comment. You are 100% correct. I assume--maybe wrongly but I don't think so--that the natural progression of the C programmer is:

- whoa cool everything is a number! Make that light blink, wipe that SDRAM chip, whiz bang!

- What the fuck is a torn read (insert any C gotcha in here)?! Everything is garbage!

- I know, I'll encapsulate "The right way to do things" in a library/new language.

- Never mind, I've decided to build websites (insert popular tech job here) for a living, but be super grouchy about it

The corollary to "I think Rust's complexity makes it impossible to delight me" is "I think C's brittleness makes it impossible to delight me." It has notes of innocence lost, nostalgia, a "simpler time", etc. Are those days gone forever, as the Dan say? Dunno.

Re:Switching to C over 'Modern' Programming Languages by scoutt on Thursday April 13, 2023 @03:42AM (#35552273)
> Is this becoming a thing now

Maybe we are entering an era where C is cool again!

Re:Switching to C over 'Modern' Programming Languages by hnarn on Thursday April 13, 2023 @04:02AM (#35552391)
Maybe it will intersect with the year of the Linux desktop :-)
Re:Switching to C over 'Modern' Programming Languages by Ygg2 on Thursday April 13, 2023 @03:58AM (#35552368)
I doubt it, even NSA is against C. Guess they got tired of all the null pointer vulnerabilities.
Re:Switching to C over 'Modern' Programming Languages by lionkor on Thursday April 13, 2023 @03:28AM (#35552193)
While I agree, I also have to say that Rust does a lot more than just solve some specific C and C++ issues. It doesnt solve all of them (e.g. logic errors, so if thats 90% of your issues you wont benefit too much), it repeats some design issues of C++ (massive complexity from the start, many ways to do the same thing), and implements a C-like unsafe{} language anyways.

If Rust was just C but with strong typing, a borrow checker and what would basically be suoer strong static analysis of pairing malloc() and free(), people would likely switch immediately.

But it isnt - its a whole different beast which by far is not perfect and repeats many issues it didnt need to repeat (e.g. terrible async like python).

Its just so good at having a compiler that tells you whats wrong that most of the other things are not that bad, and switching to Rust is likely good for 80%+ of C projects.

Re:Switching to C over 'Modern' Programming Languages by Ygg2 on Thursday April 13, 2023 @03:35AM (#35552225)
> But it isnt - its a whole different beast which by far is not perfect and repeats many issues it didnt need to repeat (e.g. terrible async like python).

Not gonna lie, I don't see too much value in async, but that said, I can see where they (the Rust devs) are coming from. It was an oft requested feature, and it was in the pipeline for ages, leading to Rust dev burnout.

That said Rust team is working on making it fully usable, albeit the space of efficient, zero-cost abstraction closures that work with lifetimes is a set of one language - Rust.

Re:Switching to C over 'Modern' Programming Languages by Ygg2 on Thursday April 13, 2023 @06:40AM (#35553466)
Not closures - async runtime.
Re:Switching to C over 'Modern' Programming Languages by flohofwoe on Thursday April 13, 2023 @04:52AM (#35552732)
> If Rust was just C but with strong typing, a borrow checker and what would basically be super strong static analysis of pairing malloc() and free(), people would likely switch immediately.

This is in a nutshell why I haven't switched to Rust. All I actually want is a small language like C, Go or Zig, but with compile time memory safety guarantees. Even if it means that a lot of 'dangerous' flexibility is removed or in an unsafe{} block (essentially a Rust--).

IMHO one problem with Rust is that it is moving too quickly into too many different directions, and as a result becoming a 'kitchen-sink language' in the tradition of C++.

Re:Switching to C over 'Modern' Programming Languages by oconnor663 on Thursday April 13, 2023 @03:17PM (#35560714)
> just C but with strong typing, a borrow checker and what would basically be super strong static analysis of pairing malloc() and free()

Most of Rust's features interact in ways that aren't obvious. For example to get the basic memory safety guarantees that the borrow checker provides, you also need:

- the "no mutable aliasing" rule

- destructive move semantics and the Copy trait

- generic containers like Mutex and (probably?) generic enums like Option and Result

- thread safety traits like Send and Sync

- closures, and closure traits like FnOnce

Of course yes, you can have "safe C" without async, and Rust 1.0 shipped without async. But I think it's notable that The Book doesn't teach async. Most of the things The Book teaches are actually necessary for memory safety to work.

Re:Switching to C over 'Modern' Programming Languages by flohofwoe on Friday April 14, 2023 @03:44AM (#35566647)
IMHO a 'rusty C' wouldn't need to cover the entire memory safety feature set that Rust provides, it just needs to be 'close enough' and otherwise warn in areas where the compiler isn't entirely sure. It can also do some checks at runtime at the cost of a slight performance hit (but again, in old C tradition this should be controllable by compile options).
Re:Switching to C over 'Modern' Programming Languages by lionkor on Friday April 14, 2023 @06:14AM (#35567672)
It doesnt matter what The Book teaches - for example a majority of Rusts web-facing ecosystem uses some async, which means

1) tokio, which uses unsafe{}, and/or

2) async functions requiring all calling functions to also be async

So, really, you can't avoid it. The ecosystem is built on the idea of NIH, which is fine, if it wasnt for so many rust features you can abuse so heavily (e.g. macros to make your own language that I then have to learn).

There are a lot of issues with the complexity Rust brings.

Re:Switching to C over 'Modern' Programming Languages by spoiler on Thursday April 13, 2023 @03:27AM (#35552187)
> they now want to talk about how “simple” and “beautiful” C is for no other reason than signaling how different you are from the zeitgeist?

It sounds to me like they keep learning languages with the same illusions and failing to take any lessons between their language exploration escapades.

All programming languages suck. It's just about finding the one that sucks the least for you (or your project/business).

They made the comparison of RPG characters and mentioned endgame frustrations. In my experience, C is the epitome of endgame frustrations (C++ maybe being worse, depending on codebases you work on); they've just yet to discover that

Re:Switching to C over 'Modern' Programming Languages by maccard on Thursday April 13, 2023 @03:36AM (#35552232)
Disagree on c++. Even if you forego the significant improvements in the last decade then: RAII and templates make it worth not using C anymore. Having to use shoddy macros for a resizeable array is just unreasonable.
Re:Switching to C over 'Modern' Programming Languages by spoiler on Thursday April 13, 2023 @04:57AM (#35552769)
I've written C++ for a long time, and I do agree that the language brings certain improvements over C. I think most people will agree with that. However, C++ can be incredibly frustrating to work with depending on the codebase.

Overall, C++ can be great choice, but it often times results in not being due to lack of rigorous discipline by everyone involved on the project.

It's a bit philosophical whether that's a problem of the tool or the craftsman, but I think it's usually a bit of both.

Re:Switching to C over 'Modern' Programming Languages by xedrac on Friday April 14, 2023 @02:40AM (#35566254)
C++ is a monstrosity, but RAII is greatly missed when using C. I'm much more inclined to use Rust these days.
Re:Switching to C over 'Modern' Programming Languages by maccard on Friday April 14, 2023 @06:52AM (#35567943)
Agreed that it's a monstrosity, but the reality is that much of that monstrosity is hiding subtle background issues that exist in C that people don't talk about. look at the implementation of std::vector, and compare that against most of the home rolled macros that (dangerously) wrap calls to realloc, and tell me which one is the monstrosity! Personally, I'm glad someone else wrote vector and that I don't need to handle that.
Re:Switching to C over 'Modern' Programming Languages by xedrac on Friday April 14, 2023 @11:03AM (#35570325)
I agree. C is absolutely terrible to use for anything that's not trivial. It may have a simple spec, but you pay dearly for it in code complexity. Its abstraction capabilities are only marginally better than writing straight assembly.
Re:Switching to C over 'Modern' Programming Languages by t-3 on Thursday April 13, 2023 @04:21AM (#35552512)
> All programming languages suck. It's just about finding the one that sucks the least for you (or your project/business).

Very true, but C is the standard language on *nixes, so it's often the one that sucks less. It also strikes a good balance between mental burden and expressiveness for writing simple programs that aren't so trivial that they're just a shell script or one-liner. Rust is just too ugly and verbose to make it what I reach for to quickly hack out a throwaway utility with.

Re:Switching to C over 'Modern' Programming Languages by pulse7 on Thursday April 13, 2023 @03:39AM (#35552252)
Maybe the zeitgeist is "being different from others for no reason"...
Re:Switching to C over 'Modern' Programming Languages by hnarn on Thursday April 13, 2023 @04:03AM (#35552398)
That’s a very good point.
Re:Switching to C over 'Modern' Programming Languages by version_five on Thursday April 13, 2023 @04:11AM (#35552452)
I started a side project in C earlier this year, and now I'm a little upset at the prospect that doing that is going to be seen as some hipster niche. I felt the same way when everyone started growing beards.
Re:Switching to C over 'Modern' Programming Languages by atoav on Thursday April 13, 2023 @03:27AM (#35552189)
As someone who should like the proposition of C after having read a few books on it I decided to avoid the language if I can. Read: I wanted to like the language, but the deeper I went into it the more I realized that the absolute knowledge of everything needed to wield it is not something that is worth aquiring.

I understand most of the historical reasons why certain things in the language are the way they are, but some of those result in really bad ergonomics and counterintuitive behavior.

So simple and beautiful is not how I would describe C even if I would love it to be that way.

Re:Switching to C over 'Modern' Programming Languages by raverbashing on Thursday April 13, 2023 @03:26AM (#35552183)
Yeah I agree

These people (with rare exceptions) quite funnily never seem to have shipped some actual product or service based on those "simpler" languages. Or if they have it's shipping their parallel implementations of basic services that every language does better than C like strings, slices, data structures, etc. And no, if your code depends on cpp macro magic, it is not helping your point.

Re:Switching to C over 'Modern' Programming Languages by coldtea on Thursday April 13, 2023 @04:51AM (#35552722)
>they now want to talk about how “simple” and “beautiful” C is for no other reason than signaling how different you are from the zeitgeist?

Given that this has been an argument for 3 decades or so, e.g. compared to C++ especially, I don't think so.

Even more so since C is not just some trendy language you pick up quickly, but needs quite a lot of time and effort to be profficcient in, to the point of appreciating its simplicity and portability/stability/etc benefits.

>Rust exists for a reason, and it solves specific problems.

Rust exists because its creators had a reason such a language was needed in mind. Doesn't mean others necessarily share it, or if they do, that they see Rust as the solution to the problem behind that reason.

Re:Switching to C over 'Modern' Programming Languages by jacquesm on Thursday April 13, 2023 @04:59AM (#35552790)
I think the main mistake that the Rust people made in their initial promotion of the language was to position it as 'a replacement for C'. No programming language has ever replaced another completely, it always ended up as just another language with its own trade offs and quirks. This even holds within a single language eco system if it isn't managed carefully, Python comes to mind.
Re:Switching to C over 'Modern' Programming Languages by throwntoday on Thursday April 13, 2023 @04:56AM (#35552762)
> Rust exists for a reason, and it solves specific problems.

But if say the foundation that supports it's development were to try asserting draconian control over it, many may reasonably be turned off.

I'll stick to C/C++ personally, rust does seem less flavor of the month but I can't get behind it if it's clear there are nutjobs at the helm.

Re:Switching to C over 'Modern' Programming Languages by up2isomorphism on Thursday April 13, 2023 @04:17PM (#35561508)
Only when a certain language community tries to promote itself as a “better” C and thinking all C code should be converted and then some people actually tried and do not agree with it.

Just write programs with your favorite language, if it is actually a “better “ one it will win, and you don’t annoy yourself and others by over promoting it. C did not start by building a evangelical strike force but bunch of programmers that actually wrote software that people have to use.

Re:Switching to C over 'Modern' Programming Languages by tpoacher on Friday April 14, 2023 @04:46PM (#35574519)
If there's a "hipster" notion here it's not that of choosing C as rebellion against Rust, but that choosing C constitutes a rebellion against Rust and only Rust, as if it's the only systems programming language worth it's salt.

E.g., explain to me like I'm 10 why you think Rust is better than, say, D.

Re:Switching to C over 'Modern' Programming Languages by shrimp_emoji on Friday April 14, 2023 @04:57PM (#35574646)
It seems to me like D is like if you took the most complicated language in the world, C++, and did even more stuff to it, like adding in an optional garbage collector. One reason it's so complicated is that "low level" programming plus OOP seem to be a terrible mix. D is trying to improve a messy room by re-organizing some things and introducing a Roomba.

Rust blazes a whole new path, with the slightly different objective of safety. It's simple and lean, almost like C. It bakes in lessons learned over the years like inheritance being overly complicated, OOP generally being overly complicated, and how dangerous systems programming can be by having modules instead of classes, composition instead of inheritance, and memory safety as a default. It also broke the false dichotomy of "fast but dangerously leaky" or "slow but safely garbage collected" by introducing borrow checking and move semantics, allowing speed and safety with no garbage collection.

D feels like a continuation down an evolutionary dead end, like teleputer cartridges in Infinite Jest.

Rust feels like an innovative fresh start, like transferring digital DRM-free files.

(If you think that makes D sound charming, I agree. But realistically I would stick with Rust. :p)

Re:Switching to C over 'Modern' Programming Languages by tpoacher on Friday April 14, 2023 @06:38PM (#35575757)
I won't lie, I lol'ed at the Roomba bit :D