News for hackers. Stuff that matters.
Re:Relive: 50 years of C, the good, the bad and the ugly by fjfaase on Friday December 30, 2022 @08:15AM (#34184703)
His final conclusion is that C has to go, just like COBOL, Fortran, and PL/I. I wonder how long it will take before C will be gone totally when you realize how much COBOL and Fortran are still around. Not so long ago, I came along a module for Python 'SciPy.interpolate' that happens to be programmed in Fortran.
Re:Relive: 50 years of C, the good, the bad and the ugly by jvanderbot on Friday December 30, 2022 @08:18AM (#34184724)
There are certainly some key libraries that use Fortran still. But I wouldn't say it's still "around". As a language for new projects, it's extremely niche. That's probably what "go" means in your comment.

I assume you're being facetious with the "recently came across", since scipy is so common, but I will add that nearly every math-intense library is a clever wrapper for some Fortran code.

I would be perfectly happy to see many hardened C libraries become the foundation of the next gen systems/ embedded languages. It does bother me slightly when we abandon the past entirely and attempt to "rewrite it in X"

Re:Relive: 50 years of C, the good, the bad and the ugly by fjfaase on Friday December 30, 2022 @08:31AM (#34184823)
No, I was not being facetious. I am not a regular user of Python, mostly have been writing/maintaining software in C++ and (in the past three years) C#. I came across it because a colleague (fluent in Python) had used scipy.interpolate in some experimentation and now the algorithm he came up with has to be implemented in C#, so I investigated whether scipy.interpolate could be called from C# and then found out that its source was in Fortran.

But just like Fortran is still used for nearly every math-intense library, mostly invisible for most of the users, I suspect that C will still be around in 50 years from now.

I agree, with his observation that C should be no longer your language of choice for new projects. I personally still prefer using C/C++ for my private software projects, simply because it is the language I am most fluent in. This year I used it for AoC.

Re:Relive: 50 years of C, the good, the bad and the ugly by auxym on Friday December 30, 2022 @08:47AM (#34184947)
Significant chunks of numpy and scipy, the "main" python packages for numerical algorithms, are wrappers around classic libraries such as BLAS, LAPACK and ARPACK, which are Fortran. Fortran was the de-facto language of scientific and numerical programming for a long time, back to the 60s even. These libraries are battle tested more than anything else out there, they literally have decades behind them, so they are industry standard and are used wherever possible.
Re:Relive: 50 years of C, the good, the bad and the ugly by jacquesm on Friday December 30, 2022 @08:21AM (#34184742)
In part that is because once a piece of software has been part of a certification process it can be very hard to replace it by something newer, no matter how shiny or how much faster. You can see quite a bit of this in aerospace, civil engineering and so on. Nobody wants to be the one to replace the Fortran based FEA package with something novel and end up being liable for a bug.
Re:Relive: 50 years of C, the good, the bad and the ugly by Decabytes on Friday December 30, 2022 @08:48AM (#34184951)
I think it will go when we have a sufficiently popular and useful systems programming language that will replace it. It has to be a language that isn't just C with some extra bits, which is why SafeC and CheckedC aren't more popular. I actually think the closest language will be Zig. It's a much simpler language than Rust and people who like C really value that simplicity. It also removes a lot of Cs baggage that make it annoying to program in. But since Zig 1.0 is unlikely until 2026 I'd say we wouldn't start seeing Zig majorly displace any C programs until about ten years after 1.0, which would be 2036. Rust 1.0 was in 2015 and we are just starting to see it in the Linux kernel ~ 8 years out, so that seems like a good timeline. Then just give it another 40 years and I could see a future where Zig and Rust replace all code where C is currently used. Sure there might be some ancient legacy systems that use C, but just like COBOL, would not be something that you would come across unless you wanted to.
Re:Relive: 50 years of C, the good, the bad and the ugly by addaon on Friday December 30, 2022 @09:25AM (#34185268)
Is there any other systems language that's even moving towards a mature ecosystem with a compiler like CompCert? It feels like this is still decades away for any realistic competitor to C.
Re:Relive: 50 years of C, the good, the bad and the ugly by keewee7 on Friday December 30, 2022 @09:04AM (#34185067)
Is there a reason Zig is taking so long to go 1.0? The language itself feels mature.
Re:Relive: 50 years of C, the good, the bad and the ugly by ptato on Friday December 30, 2022 @11:54AM (#34186854)
the self-hosted rewrite took a long time so it felt like the project had stalled for the past ~year. the team has started working on new features like the package manager, though.
Re:Relive: 50 years of C, the good, the bad and the ugly by zozbot234 on Friday December 30, 2022 @09:59AM (#34185609)
SafeC and CheckedC do nothing for temporal safety. Zig is in the same boat. There's not really a simpler alternative to Rust with the same featureset, even its direct predecessor Cyclone was in fact quite a bit harder to use. Rust itself is also improving very quickly and becoming easier to use over time.
Re:Relive: 50 years of C, the good, the bad and the ugly by elcritch on Friday December 30, 2022 @11:32AM (#34186588)
Unfortunately, Rust's core design philosophy is fundamentally opposed to much of the design philosophy that made C and C++ so popular and flexible.

It's almost the exact opposite extreme on the pendulum, where C allowed anything while Rust limits to only what the language designers conceive as proper and not just safe.

Zig can gain memory management systems like Nim's ARC which works well for system design and adds temporal safety. On the other hand Rust's trait system likely will never become an "open ended" type system like say Julia's. Heck, even overloaded function types don't seem likely in Rust.

Re:Relive: 50 years of C, the good, the bad and the ugly by estebank on Friday December 30, 2022 @03:30PM (#34189693)
What task can you do in C that you can't in Rust (or Zig, for that matter)?
Re:Relive: 50 years of C, the good, the bad and the ugly by elcritch on Friday December 30, 2022 @05:46PM (#34191035)
No, I'd count Zig as having more of an "open ended" type system / philosophy.

Though, it looks like Zig doesn't do function overloading either [1]. That's a disappointment. So you end up with `array_count`, `map_count`, etc instead of just `count`. In my way of thinking that's more work reduces readability. It's one of the paint points of C vs C++ to need `array_list_count` and `hash_map_add` instead of just saying `vec.insert(...)`.

The biggest ones for me in Rust is that it disallows extending traits for types you don't own, and the lack of function overloading. Neither of those are required for the borrow checker or safety, but it's a philosophical design decision.

1: https://github.com/ziglang/zig/issues/1251

Re:Relive: 50 years of C, the good, the bad and the ugly by AndyKelley on Friday December 30, 2022 @05:58PM (#34191134)
One of the main drawbacks of function overloading is that it can make code harder to read and understand. When the same function name is used for multiple different purposes, it is confusing for developers who are reading the code. This makes it more difficult to maintain and modify the code in the future, as developers spend extra time trying to understand the various function definitions and how they are being used. Even finding what file the function is in can be a non-trivial task.

Another issue with function overloading is that it can make code more difficult to debug. If a bug is found in one of the overloaded functions, it can be difficult to determine which function is causing the issue. This can make it more time-consuming to fix the bug and can lead to frustration for the developer. I remember debugging an issue at OkCupid and we lost many hours due to debug information being collapsed for overloads, making it look like the wrong function was being called in the debugger.

Finally, function overloading can lead to code that is more prone to errors. When the same function name is used for multiple different purposes, it can be easy to accidentally call the wrong function with the wrong arguments, which can lead to unintended consequences or runtime errors.

In conclusion, good riddance. This is what makes Zig a great language, that it doesn't have garbage like function overloading.

Re:Relive: 50 years of C, the good, the bad and the ugly by elcritch on Friday December 30, 2022 @07:44PM (#34191958)
> it is confusing for developers who are reading the code. … as developers spend extra time trying to understand the various function definitions and how they are being used.

This is a similar argument to Hungarian encoding, IMHO. A decent LSP makes it trivial to see which function is being called. The other issue you mention is a problem with the debugger/compiler, not function overloading.

> Even finding what file the function is in can be a non-trivial task.

Not really, control-click and you’re at the function def.

> it can be difficult to determine which function is causing the issue. This can make it more time-consuming to fix the bug and can lead to frustration for the developer.

Not any harder than “method” overloads, which it sounds like Zig does have.

Personally I find the opposite. Having 20 names for functions that all equate to `len` requires more mental overhead.

Re:Relive: 50 years of C, the good, the bad and the ugly by vkoskiv on Monday January 02, 2023 @12:21AM (#34214637)
> A decent LSP makes it trivial to see which function is being called.

We're talking about replacing C here. Requiring everyone depend on a hefty LSP to make sense of source code is a big ask.

Source code is text. I firmly believe that all semantic information of a piece of source code should be expressed as text in said piece of code. I already see code where the language allows the programmer to omit types from variables for 'brevity', and the assumption then is that everyone working on that code is using a fancy enough text editor that can stick in extra labels to show the missing type information. Absolutely baffling to me how people find that acceptable in any way.

Re:Relive: 50 years of C, the good, the bad and the ugly by kristoff_it on Friday December 30, 2022 @05:55PM (#34191104)
> Though, it looks like Zig doesn't do function overloading either [1]. That's a disappointment. So you end up with `array_count`, `map_count`, etc instead of just `count`. In my way of thinking that's more work reduces readability. It's one of the paint points of C vs C++ to need `array_list_count` and `hash_map_add` instead of just saying `vec.insert(...)`.

Zig doesn't have function overloading but it does have namespaced functions, so you can define your types and your "methods" on them.

https://ziglang.org/documentation/master/#struct

Re:Relive: 50 years of C, the good, the bad and the ugly by LegionMammal978 on Saturday December 31, 2022 @01:38AM (#34194248)
> The biggest ones for me in Rust is that it disallows extending traits for types you don't own, and the lack of function overloading. Neither of those are required for the borrow checker or safety, but it's a philosophical design decision.

The orphan rules are definitely necessary for coherence: otherwise, you could end up with a situation where two different crates try to implement the same trait for the same type, and there would have to be some (likely unwieldy) mechanism to resolve that.

Also, it's not that you can't implement any traits for types you don't own, it's that you can't implement traits you don't own for types you don't own. So you can still, e.g., create your own extension trait and implement it for whatever type you want. (But you can't do that while also creating a blanket impl for types implementing the original trait, which is a bit of a pain.) And, of course, if you need an object to implement a trait you don't own, you can define a newtype wrapper over it.

Re:Relive: 50 years of C, the good, the bad and the ugly by elcritch on Saturday December 31, 2022 @02:40AM (#34194469)
> The orphan rules are definitely necessary for coherence: ... and there would have to be some (likely unwieldy) mechanism to resolve that.

I think Julia, D, Nim, and others show its possible and generally easy to work with open ended type systems. I think Haskell does as well?

Though yes those come at the cost of possible conflict or user confusion, which is why I consider it a philosophical decision. It matches with the decision to not allow user code to use trait specializations in stable despite the stdlib having it.

Imports generally seem fine for controlling what gets used. Want a trait impl, import it into a module. Cargo crate features might also be a route to enforce package level decisions.

> And, of course, if you need an object to implement a trait you don't own, you can define a newtype wrapper over it, but that can also be difficult to work with sometimes.

Unfortunately that means you can't define 'default' or 'clone' traits for a type. That prevents you from using derives on your newtypes as well. That means manually implementing clone, or serde which is a PITA.

> Perhaps this situation could be improved by one of the "crate-local impl" proposals that have been floating around.

At least that'd make it somewhat easier to work with. It'd still not let end users / programmers to mix and match types and traits from different libraries without a lot of unnecessary work.

Re:Relive: 50 years of C, the good, the bad and the ugly by LegionMammal978 on Saturday December 31, 2022 @06:17PM (#34201737)
> I think Julia, D, Nim, and others show its possible and generally easy to work with open ended type systems.

Sorry, could you give an example of this? I can't find any way to extend existing types in those languages with some brief Googling.

> It matches with the decision to not allow user code to use trait specializations in stable despite the stdlib having it.

Keeping specialization unstable is much more a practical decision than a philosophical position: if they could, they would've stabilized it years ago. The problem is that specialization very quickly becomes unsound in combination with lifetimes. The compiler erases all lifetimes on types after checking them, since monomorphizing a new type for each lifetime would lead to an exponential explosion (this can't be changed at this point without redesigning the language). Therefore, users must not be able to specialize a trait impl on certain lifetime combinations (or certain lifetimes like 'static), since the compiler would have absolutely no way to tell which impl to use. And in turn, completely barring lifetime specialization becomes a daunting challenge with the existence of associated type projections and blanket impls. Specialization definitely isn't kept unstable just because they think users can't be trusted with it.

> Imports generally seem fine for controlling what gets used. Want a trait impl, import it into a module.

I don't think this would be compatible with blanket impls, since you couldn't just import every single potential impl in existence (and if you could, you'd run into conflicts). I suppose you could have a system of exporting impls, where to use a blanket impl you have to pass it another impl as input, but at that point you have new idiosyncratic system that would scare away users and would likely be far more noisy than a good newtype system.

> Unfortunately that means you can't define 'default' or 'clone' traits for a type. That prevents you from using derives on your newtypes as well. That means manually implementing clone, or serde which is a PITA.

If a foreign crate doesn't implement Default or Clone for its types, then how is the compiler supposed to derive it for your local newtypes? It can't just look into the foreign type's fields, if they aren't all public. Are you often having to work with fully public foreign types?

Overall, I get that the type system can be pretty frustrating as it stands today, but I don't see any better alternative than building better tools for defining newtypes.

Re:Relive: 50 years of C, the good, the bad and the ugly by KerrAvon on Friday December 30, 2022 @11:52AM (#34186827)
True dat. But I want to note:

- Swift has plans to incorporate temporal safety in upcoming releases. - Zig isn’t fully baked yet.

Rust will be king of that space for a while, though.

Re:Relive: 50 years of C, the good, the bad and the ugly by asveikau on Friday December 30, 2022 @01:29PM (#34188142)
Rust seems to have a lot of C++ influence to me, specifically later C++ where RAII and smart pointers became the norm. This makes sense that it came out of Mozilla, who have always had large C++ code bases.
Re:Relive: 50 years of C, the good, the bad and the ugly by anfilt on Saturday December 31, 2022 @06:24PM (#34201788)
This is honestly my biggest problem with Rust. C is a small language where the std libraries and language are defined in hundreds of pages. C++ last I checked in the latest standard was getting to almost 2000 pages.

Rust does not have a defined standard yet, but I suspect it also would be quite large.

Re:Relive: 50 years of C, the good, the bad and the ugly by WalterBright on Friday December 30, 2022 @12:53PM (#34187606)
D (in betterC mode) is C but with proper arrays, modules, advanced metaprogramming, member functions, lots of memory safety features, compile time function execution, nested functions, etc.
Re:Relive: 50 years of C, the good, the bad and the ugly by AstixAndBelix on Friday December 30, 2022 @09:05AM (#34185074)
We can replace COBOL with a Java backend to keep the enterprise feeling going, but what would C's replacement be in this case?
Re:Relive: 50 years of C, the good, the bad and the ugly by pjmlp on Friday December 30, 2022 @10:36AM (#34185943)
C++ for starters, would already be an improvment, provided string, array and vector classes with bounds checking, get used instead of raw C pointers.

Alongside RAII for resource management.

Re:Relive: 50 years of C, the good, the bad and the ugly by youarethejoke on Friday December 30, 2022 @11:50AM (#34186808)
For most embedded stuff those are just extra hassle and not worth it. C and its raw pointers and are really all you need most of the time. The need to have some discipline and expertise to produce solid code with confidence is not a bad thing in the embedded domain. If the code truly is critical you need to dive deep into verification techniques anyway.
Re:Relive: 50 years of C, the good, the bad and the ugly by pjmlp on Friday December 30, 2022 @05:06PM (#34190653)
Sure we all know that the S in IoT stands for security.
Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @12:15PM (#34208243)
Rust has already begun to replace C in the embedded space.
Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @12:14PM (#34208233)
Rust is already replacing C and C++. Ada is too. As the importance of safety increases, more safe languages will appear that can replace C and C++.
Re:Relive: 50 years of C, the good, the bad and the ugly by Sakos on Friday December 30, 2022 @09:07AM (#34185087)
Is that even possible as long as the Linux kernel is written in C? I wonder if telling people not to learn C will have a long-term effect on being able to find competent contributors to the kernel.
Re:Relive: 50 years of C, the good, the bad and the ugly by nousermane on Friday December 30, 2022 @09:12AM (#34185135)
> Linux kernel is written in C

Not exclusively in C, not anymore: https://docs.kernel.org/rust/index.html

It might take another decade for a C-free build to be possible, though.

Re:Relive: 50 years of C, the good, the bad and the ugly by attractivechaos on Friday December 30, 2022 @09:41AM (#34185430)
The Linux kernel comes with many old drivers that modern programmers have little knowledge about. It is probably more realistic to write a new kernel in rust (like Redox), targeting modern machines only.
Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @11:59AM (#34208050)
By the time it's rewritten in Rust, old drivers will be dropped due to lack of demand for them.
Re:Relive: 50 years of C, the good, the bad and the ugly by c7DJTLrn on Friday December 30, 2022 @09:16AM (#34185163)
Only a decade? I don't think so.

AFAIK Torvalds has also stipulated that any Rust code needs to be mirrored in C.

Re:Relive: 50 years of C, the good, the bad and the ugly by michaelsshaw on Friday December 30, 2022 @09:38AM (#34185394)
This right here. Rust only JUST got added to the kernel in 6.0 and I doubt that it will replace 30 years of C development any time soon.
Re:Relive: 50 years of C, the good, the bad and the ugly by mustache_kimono on Friday December 30, 2022 @10:48AM (#34186086)
> AFAIK Torvalds has also stipulated that any Rust code needs to be mirrored in C.

Do you have a cite for this? I hadn't heard this at all.

Re:Relive: 50 years of C, the good, the bad and the ugly by c7DJTLrn on Friday December 30, 2022 @11:01AM (#34186231)
Apologies, I can't find a source. I probably read it on LWN somewhere. Linus wouldn't dip both feet into the water at the same time. I'm confident he's said that the kernel needs to be buildable without Rust if need be.
Re:Relive: 50 years of C, the good, the bad and the ugly by mustache_kimono on Friday December 30, 2022 @12:11PM (#34187076)
> I'm confident he's said that the kernel needs to be buildable without Rust if need be.

FWIW that's not the same thing? That's simply CONFIG_RUST=n, not "You have to write this driver twice in two different languages".

Re:Relive: 50 years of C, the good, the bad and the ugly by unwind on Friday December 30, 2022 @09:14AM (#34185154)
Wow that sounds fantastically optimistic, or pessimistic depending on your point of view I guess.

Rewriting that amount of code in ten years sounds very very hard, at least.

Re:Relive: 50 years of C, the good, the bad and the ugly by ImprobableTruth on Friday December 30, 2022 @09:25AM (#34185264)
They said a C-free build. For that you'd need to "just" rewrite the core kernel, which will be 150-200k lines, and the drivers + arch specific parts for one system. Still a tall order, but a decade isn't unrealistic if Rust proves itself.

Now, rewriting everything, including all the legacy drivers? Yeah, never happening even if Rust succeeds utterly.

Re:Relive: 50 years of C, the good, the bad and the ugly by chillingeffect on Friday December 30, 2022 @09:49AM (#34185516)
Once they get to that point, a new language will be available that makes up for the things Rust is still short on.
Re:Relive: 50 years of C, the good, the bad and the ugly by Sakos on Friday December 30, 2022 @02:11PM (#34188704)
Maybe there's a case to be made for a multi-language kernel. Rust is the first step. Maybe it'll make sense at some point to keep Rust, but add another language.
Re:Relive: 50 years of C, the good, the bad and the ugly by Sakos on Friday December 30, 2022 @09:29AM (#34185306)
A significant amount of the lines of code in the kernel are for drivers (7 of 12 million lines?).

A potential strategy would be to set a date where any new drivers must be written in Rust. Deprecate every non-Rust driver on a date after that. Focus on rewriting only the drivers necessary for current hardware platforms (and some sensible/arbitrary cut-off going back x years). Then set a final deadline for a New Linux kernel release that removes all deprecated/C drivers.

I would blindly estimate that entire process to take 10-20 years (not including the time needed for debating the whole thing).

Then somebody "just" needs to rewrite the rest of the code.

So, uh, any volunteers?

Re:Relive: 50 years of C, the good, the bad and the ugly by tristanbvk on Friday December 30, 2022 @09:29AM (#34185300)
I don't see such a feat taking place in the next decade, you need highly dedicated people. I can see new code being written in Rust but a C free build sounds like something that really won't be happening anytime soon.

I wish something like it could happen, but I am causyiously optimistic.

Re:Relive: 50 years of C, the good, the bad and the ugly by tmtvl on Friday December 30, 2022 @11:26AM (#34186521)
As long as there isn't a Rust compiler written in Rust (there is a transpiler to LLVM bytecode, but that gets compiled by a C++ compiler, same for GCC-rs) I don't think a C-free (or a C++-free) build will be possible at all, so I'm guessing it'll take somewhere in the 60-100 year range.
Re:Relive: 50 years of C, the good, the bad and the ugly by ansible on Friday December 30, 2022 @11:46AM (#34186754)
There are some open issues and features like inline assembly that aren't supported, but a moderately complete backend exists now:

https://github.com/bjorn3/rustc_codegen_cranelift

The compiler frontend is already written in Rust.

Re:Relive: 50 years of C, the good, the bad and the ugly by estebank on Friday December 30, 2022 @03:38PM (#34189805)
Honest question: what would the engineering rationale be behind dropping LLVM entirely and have rustc have its own code generation backend? There are two out there that might be interesting, one uses gcc and another is called cranelift, but it isn't the default and focuses exclusively on compilation speed for debug binaries.
Re:Relive: 50 years of C, the good, the bad and the ugly by tmtvl on Friday December 30, 2022 @06:36PM (#34191464)
Well people keep telling me that C/C++ code should be replaced by Rust for ~safety~ reasons, and LLVM is a C++ project, so...

Let's say it would avoid all the memory bugs in LLVM, that would doubtlessly make it worth throwing away the LLVM implementation (avoid sunk cost fallacy).

Re:Relive: 50 years of C, the good, the bad and the ugly by tialaramex on Friday December 30, 2022 @07:14PM (#34191767)
If anything, it's more likely that the desirable choice is to shift LLVM to Rust.
Re:Relive: 50 years of C, the good, the bad and the ugly by sylware on Friday December 30, 2022 @09:15AM (#34185158)
C syntax is already way too rich and complex, not to mention the bazillions of gcc extensions required to compile the linux kernel.

Namely, if it has to be "replaced", that would be with something with a much simpler syntax, which will require a bit more of finger power. We don't want to find ourself locked-in by very few compiler vendors (open source or not), that only because it is not reasonable to code a real-life alternative with a small team of averagely skilled devs in a reasonable amount of time.

This language should build on C though: no enum/typedef/_generic/switch/etc, only 1 loop keyword (loop{}) only explicit sized types, no integer promotion, no implicit casts (except maybe void* pointers but number literal casts should be) but explicit casts (compile-time and runtime, without that horrible c++ syntax), explicit compile-time const (we have only runtime consts which could be optimized as compile-time consts), enforce extern for functions (and don't try to put the binary format, elf/coff/etc, semantics into the language syntax or worse, the OS interface semantics), etc.

With enough discipline (and compiler warnings), we could get close to such language.

I did not check the latest and greatest rust syntax, but is what's above its explicit goals?

That said, I am a "everything in 64bits RISC-V assembly with x86_64/arm64 legacy ports kind of guy"... if RISC-V is successful (I wish). We could think of high-level language interpreters (coded in assembly, for instance a RISC-V coded python/lua/javascript/etc interpreters).

Re:Relive: 50 years of C, the good, the bad and the ugly by tristanbvk on Friday December 30, 2022 @09:32AM (#34185330)
These are good ideas. The simplicity here is what I am going for.
Re:Relive: 50 years of C, the good, the bad and the ugly by sylware on Friday December 30, 2022 @07:33PM (#34191891)
On the long run, it all depends on syntax stability which is tightly coupled with its complexity.

The "benchmark" to run to evaluate syntax complexity toxicity, for a compiled language, is how long an alternative compiler written by a small teams of averagely skilled devs, or even one individual averagely skilled dev, can stay a "real life" "working" alternative.

Mid-term/long-term planned obsolescence of computer language syntax is really...

Oh, and in my previous post: for compile time constants we can use static consts, my bad.

Re:Relive: 50 years of C, the good, the bad and the ugly by flohofwoe on Friday December 30, 2022 @09:44AM (#34185455)
TBH that sounds a lot like Zig (it has two loop keywords though: for and while, but those are for different use cases - for is only for iterating over ranges, and while is the 'vanilla loop' for everything else). Zig does introduce a bit of syntax pollution for its comptime features though (mainly the 'inline' variants of existing keywords), and it adds some syntax sugar for the builtin error handling and optionals - so it's essentially a dismantled C which is then slightly extended into a different direction.
Re:Relive: 50 years of C, the good, the bad and the ugly by sylware on Saturday December 31, 2022 @06:23AM (#34195450)
This is one too many loop keyword.

And something must be done about breaking changes of the syntax (or any never ending "features" additions).

We all know that some syntaxic constructs will be nasty in the end and will reasonably need fixing (basically, to keep them excrusiatingly simple from a compiler writing point of view). I am thinking about something like "syntax breakage provisions" from the language authors: for instance, no more than 4 iterations of major syntax breakages, then the language syntax will be frozen for forever.

Whatever, I am a everything in assembly kind of guy (with high-level language interpreters written themselves in assembly).

All that is a thought experiment for me, nothing more.

Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @12:20PM (#34208310)
Doesn't Modula-2, Oberon or Ada fill your checkboxes?
Re:Relive: 50 years of C, the good, the bad and the ugly by pjmlp on Friday December 30, 2022 @09:24AM (#34185257)
It won't go away, but just like it happens with COBOL, Fortran, and PL/I, you won't see anyone dreaming of coding C until the end of their working days.

Or maybe they will, given how much consultants in those languages happen to be paid, as no one else wants to touch them.

Re:Relive: 50 years of C, the good, the bad and the ugly by pantalaimon on Friday December 30, 2022 @09:35AM (#34185364)
But coding C is actually fun!
Re:Relive: 50 years of C, the good, the bad and the ugly by Ygg2 on Friday December 30, 2022 @12:44PM (#34187483)
Sure. But debugging sure isn't. Null, null terminated strings, data races, segfaults...
Re:Relive: 50 years of C, the good, the bad and the ugly by Koshkin on Friday December 30, 2022 @01:48PM (#34188420)
No, no - debugging is actually where all the fun is!
Re:Relive: 50 years of C, the good, the bad and the ugly by Ygg2 on Friday December 30, 2022 @04:11PM (#34190167)
I'm not masochistic enough, I guess.
Re:Relive: 50 years of C, the good, the bad and the ugly by rightbyte on Friday December 30, 2022 @10:08AM (#34185685)
> you won't see anyone dreaming of coding C until the end of their working days.

I do dream about that. Just being able to tag along while some programmers learn their Xth framework as a language.

Maybe someday I might concede and move on from C89 to C99.

Re:Relive: 50 years of C, the good, the bad and the ugly by diydsp on Friday December 30, 2022 @11:13AM (#34186367)
Same here. Ive got so much experience and libraries ive written i can marshall. They've been ported across small and large platforms since before github and google. Ive been maintaining them since the 5.25" disk age. New C projects aren't precarious to me. Watching a bunch of architects with no embedded experience try to make C++ happen on microcontrollers in the other hand...
Re:Relive: 50 years of C, the good, the bad and the ugly by KerrAvon on Friday December 30, 2022 @11:57AM (#34186910)
If I may ask, what projects do you work on where C89 is still useful? Embedded ROMs for tiny processors in some niche segment?
Re:Relive: 50 years of C, the good, the bad and the ugly by rightbyte on Friday December 30, 2022 @02:17PM (#34188785)
Ye well Linux is moving from GNU C89 to GNU C11 so maybe it is time for me to move on.

I don't think there is any reason to choose C89 over C11 other than fear of new compiler bugs and compatibility with old compilers?

Re:Relive: 50 years of C, the good, the bad and the ugly by KerrAvon on Friday December 30, 2022 @11:56AM (#34186896)
C has enough actual fans that I bet it never really goes away, but it won’t be useable in professional contexts after a while other than for maintenance, because people outside tech will start to call bullshit on the EULA liability shield.
Re:Relive: 50 years of C, the good, the bad and the ugly by lelanthran on Friday December 30, 2022 @02:33PM (#34188988)
> C has enough actual fans that I bet it never really goes away, but it won’t be useable in professional contexts after a while other than for maintenance, because people outside tech will start to call bullshit on the EULA liability shield.

That's an extraordinary claim indeed; if people outside tech were going to call bullshit on EULAs as a liability shield, they would've done so in the last 50 years of software sales.

Reliability or the lack thereof has never been an impediment to some piece of software getting popular, but to me, you appear to believe that people want more reliability from software than they have been getting thus far.

Your belief is at odds with reality.

Re:Relive: 50 years of C, the good, the bad and the ugly by pjmlp on Friday December 30, 2022 @05:24PM (#34190801)
They already started with small steps.

- Return of goods in digital stores

- Warranties in consulting projects, requiring free of charge fixes up to one year

- Cybersecurity bills

It will only get better from now onwards.

Re:Relive: 50 years of C, the good, the bad and the ugly by flohofwoe on Friday December 30, 2022 @09:31AM (#34185317)
A good bet is that a technology will be around at least as long as it has been around (I think there's also a 'named law' for it). So I fully expect C to be around in one way or another for the next 50 years, it probably won't be as important anymore, just as COBOL or Fortran are not as important as they used to be.

One reason for C to disappear completely would be if computer architectures would change so much that current programming languages no longer even map to those new architectures (e.g. all the existing programming languages would need to be dumped anyway).

Re:Relive: 50 years of C, the good, the bad and the ugly by ReactiveJelly on Friday December 30, 2022 @09:35AM (#34185359)
https://en.wikipedia.org/wiki/Lindy_effect

> The Lindy effect (also known as Lindy's Law[1]) is a theorized phenomenon by which the future life expectancy of some non-perishable things, like a technology or an idea, is proportional to their current age. Thus, the Lindy effect proposes the longer a period something has survived to exist or be used in the present, the longer its remaining life expectancy.

Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @12:12PM (#34208215)
While C and C++ have been around longer than COBOL was when building new systems it it was halted, at least COBOL does its job well while C and C++ don't due to their lack of safety. Also, COBOL is more difficult to replace than C and C++ are. I expect C and C++ code to start being seen as dangerous and money will be spent to eradicate it due to its potential to be a security risk in this online world.
Re:Relive: 50 years of C, the good, the bad and the ugly by hgs3 on Friday December 30, 2022 @09:38AM (#34185396)
C is the best abstraction for many problem domains and that isn't going to change. I understand why folks coming from higher-level languages would dislike it, but for anyone coming from assembly it's a godsend.

The speaker discourages C for new projects, but that says more about the problem domains they work in than C itself. C is what it is because the hardware and assembly language are what they are. Folks who want a safer C should design a new hardware architecture with a "safe" assembly language and a new low-level language that targets it.

Re:Relive: 50 years of C, the good, the bad and the ugly by sirsinsalot on Friday December 30, 2022 @09:51AM (#34185534)
Anyone discouraging a particular tool without actual context of the problem being solved gets zero respect from me.

It's a massive red flag that they don't know enough to be useful.

C is great for the things C is great for, however small that range may or may not be now and in the future.

Any other stance is reductive and misleading.

Re:Relive: 50 years of C, the good, the bad and the ugly by KerrAvon on Friday December 30, 2022 @11:48AM (#34186777)
Exactly what, in the year 2023 C.E., is C great for?

I’ve been writing C since 1991 and I can’t think of anything where I wouldn’t start a new project in some other language. There are many interesting choices of varying maturity in the low-level systems programming space: Zig, Rust, Crystal, D, Swift (if the standard library ever gains support for system-level programming). Even the “better C” subset of C++ will allow you to avoid certain classes of security bugs completely.

I don’t think C is even merely adequate for anything at this point; defaulting to memory safety is table stakes in any domain where C was once dominant.

Re:Relive: 50 years of C, the good, the bad and the ugly by matheusmoreira on Friday December 30, 2022 @12:40PM (#34187441)
> Exactly what, in the year 2023 C.E., is C great for?

Writing readable code. I like Zig and Rust too but at the end of the day they just aren't C.

Re:Relive: 50 years of C, the good, the bad and the ugly by fncslothouber on Friday December 30, 2022 @12:06PM (#34187023)
Memory safety / security is important for a subset of all possible applications. It is not important for _all_ applications.

If I use a micro controller to control a string of leds I do not care about security/memory safety. But I do care about being as close to the metal as possible, and being able to understand the compiled code.

Re:Relive: 50 years of C, the good, the bad and the ugly by bonzini on Friday December 30, 2022 @12:40PM (#34187450)
To control a string of LEDs, something like Forth (or some other p-code virtual machine) is going to be just as good as C. PIC microcontrollers have always had BASIC as an option for example.

But many microcontrollers these days will likely have a TCP/IP stack, perhaps even crypto, even if it is to control a string of LEDs via MQTT or Modbus TCP.

Re:Relive: 50 years of C, the good, the bad and the ugly by fncslothouber on Friday December 30, 2022 @03:35PM (#34189776)
Forth would also be a nice choice.

Give you another example. A watch, not an apple watch, but a simple Casio watch. One that does time, alarm and a stopwatch. Not connected to anything. What is important here is the battery life, so the less code the better. C would be a fine choice here. All additional code to prevent security breaches would be a complete waste here.

Give another example. As my day-job I develop embedded software for the railways. Current system I work on operates the brakes when the train goes too fast. Not connected to the internet, and no connection would even be allowed. Written in C. One because it is simple to understand and the developer can focus on getting the functionality correct. Secondly because there is a wide choice of additional tooling and standards that is required to get the application certified.

Re:Relive: 50 years of C, the good, the bad and the ugly by ptx on Friday December 30, 2022 @12:48PM (#34187555)
If people rely on the LEDs working correctly or if the controller has any kind of connection to another system (which could be leveraged by an attacker to penetrate deeper into the network) it seems to me that security and memory safety would still be important.
Re:Relive: 50 years of C, the good, the bad and the ugly by fncslothouber on Friday December 30, 2022 @02:00PM (#34188562)
Not everything is or needs to be connected to the Internet.

There are plenty of things that are controlled by a micro controllers that do not have a network connection.

Re:Relive: 50 years of C, the good, the bad and the ugly by estebank on Friday December 30, 2022 @03:22PM (#34189604)
Not everything needs to be connected to the Internet, and not every micro controller is running a non-mission critical task.

A micro controller hitting a memory safety bug that causes the LEDs to present invalid output can have real world consequences. Even if the micro controller isn't directly actuating machinery, it might cause an operator to incorrectly act because they were mislead.

If the micro controller is running Christmas lights, it might be fine if it falls over, no one will die, but I would still call that a manufacturing defect.

Re:Relive: 50 years of C, the good, the bad and the ugly by pjmlp on Friday December 30, 2022 @05:18PM (#34190745)
Only because liability still isn't a thing across all levels of software development.

Thankfully returns in digital stores, warranties in consulting projects, lawsuits in business losses and cybersecurity bills are slowly changing that.

Re:Relive: 50 years of C, the good, the bad and the ugly by Koshkin on Friday December 30, 2022 @12:02PM (#34186969)
> C.E.

There.

Re:Relive: 50 years of C, the good, the bad and the ugly by jeff-davis on Friday December 30, 2022 @01:40PM (#34188280)
The consequences of C in long-lived software are somewhat known. Granted, the track record of C is mixed, but many important projects have been successful with it.

Rust is exciting and proving itself about as rapidly as such a language could be expected to do. But there are big questions around how all of this plays out in a long-lived project. There's a good argument that C's simplicity is an asset here.

I like Rust a lot and have done some cool stuff with it. I believe the challenges of long-lived projects will be solved. But at the same time, I admit that there are a lot of other factors (including non-trchnical ones). If you pick a language that doesn't last for whatever reason, and you have a couple decades worth of code, the options are grim.

Re:Relive: 50 years of C, the good, the bad and the ugly by addaon on Friday December 30, 2022 @03:45PM (#34189885)
> Exactly what, in the year 2023 C.E., is C great for?

Implementing low-level code that is important enough to prove correct, without going through the additional effort of de novo proving your entire toolchain is correct.

Re:Relive: 50 years of C, the good, the bad and the ugly by tmtvl on Friday December 30, 2022 @05:51PM (#34191070)
Yeah, Ada is pretty great, it takes the best things from Pascal and combines it with unparalleled reliability.
Re:Relive: 50 years of C, the good, the bad and the ugly by doodlesdev on Friday December 30, 2022 @03:06PM (#34189395)
C is a great language to program a PDP-11 in the 1980s. And that's it. There are SO MANY alternatives for so many different use cases nowadays, it's just hard to justify using C anywhere whatsoever.
Re:Relive: 50 years of C, the good, the bad and the ugly by erik_seaberg on Saturday December 31, 2022 @02:05AM (#34194340)
It was practical for self-hosted PDP-11 development, which was tough. They could have cross-compiled a few other languages on a bigger machine, if only they had one.
Re:Relive: 50 years of C, the good, the bad and the ugly by pjmlp on Friday December 30, 2022 @09:56AM (#34185581)
Languages like PL/I, NEWP, BLISS, Modula-2 did it much better, but they didn't come with a free beer OS.
Re:Relive: 50 years of C, the good, the bad and the ugly by Koshkin on Friday December 30, 2022 @12:01PM (#34186955)
> C is the best abstraction for many problem domains

It's really not, though. What C is an abstraction of is computer architecture as it existed by the late 1960s.

Re:Relive: 50 years of C, the good, the bad and the ugly by hgs3 on Friday December 30, 2022 @02:05PM (#34188632)
> It's really not, though. What C is an abstraction of is computer architecture as it existed by the late 1960s.

I don't follow. Barring micro-code, hardware is designed for executing either RISC or CISC instructions. If anything, the industry has matured and we see less esoteric ISA's today than in the 1960s.

Re:Relive: 50 years of C, the good, the bad and the ugly by estebank on Friday December 30, 2022 @03:25PM (#34189643)
A modern low level labguage would expose you to the concepts of cache lines and homogeneous and eterogeneous cores directly, with locality awareness to recognize false sharing. It would be something suitable to program the Cell architecture from PS2.
Re:Relive: 50 years of C, the good, the bad and the ugly by addaon on Friday December 30, 2022 @03:46PM (#34189896)
What about those of us working on microcontrollers that use TCM rather than cache, and that don't have multiple cores? C sure seems like a good fit…
Re:Relive: 50 years of C, the good, the bad and the ugly by hgs3 on Friday December 30, 2022 @05:32PM (#34190898)
Those are fair points, but they're probably too specific to the architecture to incorporate in C's general execution model. They're better exposed through platform specific programming interfaces like OpenMP or CUDA. Even a domain specific language, like GLSL, may be more appropriate.
Re:Relive: 50 years of C, the good, the bad and the ugly by turndown on Friday December 30, 2022 @10:56PM (#34193394)
I think that the general point being made here is that C’s general execution model, as you call it, really is just a PDP-like computer because that is what they had when making C.
Re:Relive: 50 years of C, the good, the bad and the ugly by hgs3 on Saturday December 31, 2022 @11:37AM (#34198053)
The confusion I have is that the original commenter makes it sound like the abstract machine C is designed for is not relevant today. While modern desktop hardware may use various techniques to improve performance, like cache lines or specialized cores, they are an implementation detail of that abstract machine. I would not expect C to expose these hardware specifics because C targets a lowest common denominator, from consumer desktop hardware to microprocessors. If the criticism is that C is too general, then that's fair but also applies to every C competitor: Rust, Zig, D, etc... It's debatable how much these languages should include versus exposed by vendor specific API's. Perhaps we need a fork of C designed exclusively for modern desktop hardware.
Re:Relive: 50 years of C, the good, the bad and the ugly by w10-1 on Friday December 30, 2022 @01:03PM (#34187774)
> Folks who want a safer C should design a new hardware architecture with a "safe" assembly language and a new low-level language that targets it

Would that be LLVM's IR or MLIR (https://mlir.llvm.org)?

Re:Relive: 50 years of C, the good, the bad and the ugly by kovac on Friday December 30, 2022 @09:41AM (#34185426)
Can C really completely go away as long as there's embedded programming? Are there any other alternatives for that domain?
Re:Relive: 50 years of C, the good, the bad and the ugly by Zagitta on Friday December 30, 2022 @10:14AM (#34185733)
Rust is rapidly picking up steam in the embedded sphere :-)

Unfortunately it's an industry with a lot of stubborn old people so I don't see any major changes happening until they've retired but I'm willing to bet that async is going to revolutionize embedded development. Being able to await interrupts and doing efficient cooperative scheduling while writing straight forward code is a massive QoL improvement which is what embassy is enabling: https://embassy.dev/

Re:Relive: 50 years of C, the good, the bad and the ugly by pjmlp on Friday December 30, 2022 @10:34AM (#34185923)
Yes, compilers for C++, BASIC, Pascal, Ada are around, mostly commercial and people pay to keep those companies in business, for powerfull microcontrollers where real time GC is an option, there are Oberon, .NET and Java as well.

There are surelly other factors that weight in using C, but not for lack of options (in many cases).

Re:Relive: 50 years of C, the good, the bad and the ugly by Tomte on Friday December 30, 2022 @10:00AM (#34185615)
There are embedded devices programmed in other languages, you know, and there have been for decades. In Ada, for example. Which is an even better fit to the domain than C (better ways to describe hardware idiosyncracies).
Re:Relive: 50 years of C, the good, the bad and the ugly by KnowOneYouNo on Friday December 30, 2022 @01:15PM (#34187939)
Ada is a much better and modern alternative for embedded, real-time and/or systems programming. Its mature, (although still evolving) and very scalable from very, very small to very, very large systems. It also supports interoperability with C and C++. It is a primary language in GCC. See https://ada-lang.io/ and https://learn.adacore.com/

Unfortunately Ada is held back by a genuine lack of awareness and some old misinformation baggage.

Re:Relive: 50 years of C, the good, the bad and the ugly by Hemospectrum on Friday December 30, 2022 @07:33PM (#34191892)
As strange as it might sound, the success of Rust seems to have reopened some doors for Ada. People in both communities are aware of this and already collaborating on various projects to mutual benefit.
Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @12:06PM (#34208134)
Rust and Ada are both seen as 'safe' languages that prevent many unsafe actions by programmers.
Re:Relive: 50 years of C, the good, the bad and the ugly by micronian2 on Wednesday January 04, 2023 @02:39PM (#34250313)
I haven't used Rust, but many of the comments and articles I have read about the benefits of the language and the strong desire for develop robust and/or safe software are virtually the same as what Ada supporters have been claiming for decades.

It's a good thing more people are realizing we really need to stop settling for C and C++, stop investing more money into tools that simply compensate for the weak foundation of those languages, and finally adopt safer alternatives.

Re:Relive: 50 years of C, the good, the bad and the ugly by micronian2 on Wednesday January 04, 2023 @02:25PM (#34250151)
This! I have mainly programmed in C in my career (note: I also have experience with C++ on multiple projects and to a lesser extent with C# and Java). In almost all the embedded projects I have been on, Ada would have been a far better choice because it would have helped avoid whole classes of common software bugs and thus less costly to maintain. This is especially true with bugs reports and vulnerabilities that would be discovered on systems that were already deployed.

People normally think that C is the best for low level embedded programing, but from my experience, it pales in comparison to the amount of low level control and type safety that Ada provides, even when you restrict yourself to a small subset of the language (note: Ada is often used on barebone systems and without an Ada runtime). Given the interoperability Ada has with C, it means you don't have to rewrite everything in order to incorporate it into existing code bases.

Re:Relive: 50 years of C, the good, the bad and the ugly by jillesvangurp on Friday December 30, 2022 @10:05AM (#34185651)
In a way, it's already happening. Many big tech companies are now defaulting to other languages than C and are actively discouraging the use of C or C++ for new code. They still have a big vested interest in maintaining existing code of course. That's not going to disappear overnight obviously.
Re:Relive: 50 years of C, the good, the bad and the ugly by pillefitz on Friday December 30, 2022 @08:17PM (#34192229)
Do you have examples? Is it all going towards Rust or are there other big tech-backed contenders?
Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @12:04PM (#34208107)
I read recently that parts of the code for Artemis are written in Ada. Ada is also used on the ISS. Makes me wonder who besides NASA might be using Ada due to its' safety.
Re:Relive: 50 years of C, the good, the bad and the ugly by jcranmer on Friday December 30, 2022 @11:22AM (#34186481)
My prediction is that C will die off as a language long before Fortran and COBOL. What keeps a language like Fortran alive is that it is used in an application niche where rewriting is done at best ship-of-Theseus style, and the friction of using a new language for a component far outweighs the benefits of doing so (weather models are a good example here). For COBOL, it remains in applications where the cost of a switch or rewrite includes a low risk of catastrophic, and therefore expensive, failure (see Southwest Airlines for a very public and recent example of such a failure).

C does have a similar kind of niche at first glance: systems programming is of course conservative, rewriting everything is unlikely, and of course, C is the language used for ABI. Except on closer inspection, that moat is remarkably shallow. Being the language of ABI means that every competitor language has some way to speak C guaranteed, so the friction of rewriting systems software Ship-of-Theseus-style is much lower (though still nonzero). Systems software is rewritten from scratch on a much higher cadence: in the last 20 years or so, most of the userspace system glue for Linux has been replaced (e.g., systemd, iproute2, pulseaudio, wayland). And we've learned over the past few decades that there's no practical way to fix C's fundamental unsafety issues with software engineering practices, and C's committee is too conservative to consider retrofitting the necessary features to be able to fix unsafety at a language level (to say nothing of getting people to use it).

There is already a small clutch of languages that can serve C's niches that don't have the same fundamental unsafety issues, and right now, we're sort of at an experimental stage of system software trying them out. It's not unreasonable to believe that within a decade or so, one or more of these languages would be considered a standard, safe choice for implementing new systems software--and the use of C in new projects will start dropping. At some point, the proliferation of non-C systems projects will make people point out that having these components talk through C's ABI is too limited in functionality, and a system will change its ABI from C to some other language. And once it is no longer the language of ABI, C will lack its moat that keeps it alive, and it will start dying, though its death will be a slow, agonizing death.

Re:Relive: 50 years of C, the good, the bad and the ugly by Wadajot on Friday December 30, 2022 @12:46PM (#34187520)
> that happens to be programmed in Fortran.

SciPy is a highly optimized library and Fortran is faster than C for some tasks:

https://stackoverflow.com/a/146186/3383640

Re:Relive: 50 years of C, the good, the bad and the ugly by Tozen on Monday January 02, 2023 @01:41AM (#34215071)
The problem is that there isn't anything to replace C, that would be acceptable enough. C has become a quasi protocol, and used in exchanges between languages.