Live data from Hacker News

50 years of C, the good, the bad and the ugly [video]

streaming.media.ccc.de

251–257 of 257 posts

Re: 50 years of C, the good, the bad and the ugly [video]

#251
post #223

Earlier quoted context omitted.

> If you want a different semantics at the source level, e.g. overflow is an exception, then the compiler needs to emit additional code. Yes, and which is exactly what I hinted at with my question to your comment. With the HW we have today, implementing such semantics without an extra hit is not possible and which is why I thought your comment wasn't completely fair but coming from more theoretical stance.

Checking for overflow is basically adding a conditional branch (usually to out-of-line code) after arithmetic. It's very cheap, almost free, if there are enough execution units, I-cache isn't a bottleneck, etc etc. But yeah, it is theoretically an overhead, which is why I avoided it for Virgil. I suppose range analysis can eliminate many overflow checks, e.g. in counted loops, but it's not completely zero cost.

> Checking for overflow is basically adding a conditional branch (usually to out-of-line code) after arithmetic.

Yes, but now as well you have to return a value to communicate the overflow to the call site. And call site has to check for that value and that's yet another and another ... and another branch. Depends how deeply you want to propagate that error and decide how (?) to deal with it, this will grow the code size, which can contribute to the higher frequency of I-cache misses and page-faults, but it can also inhibit compiler optimizations.

On the CPU level, I think there also could be an attached cost as well in case some of those branches end up as entries either in branch-target (BTB) or branch-order (BOB) buffers or both. Sizes of these buffers are quite scarce so ending up with the unfavorable ratio of check-for-overflow entries vs entries occupied by other type of branches found in the code is something that will put more pressure to our branch-prediction unit. More "important" branches will now more frequently start to lack their entry in the branch history simply because of the fact that we started sprinkling check-for-overflow branches. And yet we know that branch misprediction is the costliest operation (15-20 cycles) we can encounter in the CPU pipeline.

Also, I think a bigger picture must be observed in this context. E.g. what is the percentage of arithmetic operations some big real-world sized binaries contain? I'd figure that in average it would be a sizeable amount, and in ones with a lot of math even more so. And then I wonder what we could observe if we applied the check-for-overflow transformation to all such signed-arithmetic operations.

I'm aware that there are some artificial benchmarks showing that there's no cost attached to branches which are essentially never taken but it makes me wonder if that cost would really be zero if we exercised that change on the actual code instead. For at least the reasons from above.

Re: 50 years of C, the good, the bad and the ugly [video]

#252
post #249
post #99

I'm trying to build a language that translates directly to C. I will just implement some features of the language in C, with some headers I can already find. It feels like it's the best way I want to do this. That way, a C compiler can do a lot of work I really don't want to do, C already has backends, optimizers, etc etc. All I want is a C-like language with native strings, hash map and list, tuples python indentati…

or Vlang ( https://vlang.io/ ), which can compile to C, and has a C2V transpiler.

Yes, it's quite a nice language, but it still has features I wish it didn't.

It's close to what I want to do, except it doesn't have python indentation, and it doesn't have tuples.

Re: 50 years of C, the good, the bad and the ugly [video]

#253

Earlier quoted context omitted.

If somebody's expecting something other than a C string then we unsurprisingly have gratuitous complications. If everyone agrees on the C string though, it just interoperates as-is. Code compiled for some 16-bit microcontroller can just shove the C string into its transmit buffer, and on the other end, code compiled for 64 bit big-endian Power PC receiver just uses it as-is.

C is the biggest mistake in the software industry since the beginning of software. The people that worship C only do so because they haven't seen the better paths the software industry could have chosen.

This is ridiculous hyperbole.

Nobody "worships" C and people who have positive experiences with C often have exposure to higher level languages.

You can find strengths or upsides in C and still acknowledge faults, and still acknowledge merits elsewhere.

Re: 50 years of C, the good, the bad and the ugly [video]

#254
post #30

Earlier quoted context omitted.

Can C really completely go away as long as there's embedded programming? Are there any other alternatives for that domain?

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 mis…

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: 50 years of C, the good, the bad and the ugly [video]

#255

Earlier quoted context omitted.

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 mis…

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.

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: 50 years of C, the good, the bad and the ugly [video]

#256
post #250

Earlier quoted context omitted.

C is a garbage language. It has a lot of undefined behaviour. It isn't safe. It isn't even strongly typed. It's only marginally better than a macro assembler. C programmers consider that a virtue but programmers who want to write safe, robust code, know C is garbage.

"One man's garbage is another man's treasure."

Those people are called hoarders.

Re: 50 years of C, the good, the bad and the ugly [video]

#257
post #247

Earlier quoted context omitted.

Pascal, at least the original specification, does have a few flaws. It was intended to run as P-code in a VM so you wouldn't expect it to be as good as running directly on the hardware. The successor to Pascal, which fixed it's problems, was Modula-2, which is vastly superior to C. Unfortunately by the time it came out and started becoming available, it was too late for it to compete fairly with C. Ada is comparable…

Pascal was and is continually evolving. A strong argument can be made that Object Pascal was the "successor" of Pascal, and that happened in 1985/86. After Apple and Wirth developed Object Pascal, Borland added the OOP extensions to their version soon afterwards. Turbo Pascal had quite a long run, and some are still using it. The Delphi dialect of Object Pascal came out in the early 1990s and Free Pascal came out in…

Modula-2 has many new features that make it better than Pascal. It is not merely a Pascal with some issues fixed.

One small thing I like about Modula-2 is an improvement in the syntax where BEGIN is not required after conditionals and loops.

Post reply on HN