Tag: programming languages

Why is C Preferred for Some Scenarios?


What are common uses of C in the real world outside of embedded and OS dev? from C_Programming

tim36272
Consider expanding what you normally think of as “embedded”: I develop embedded C applications but our box has the same processing power as a gaming computer.

Most safety-critical applications are written in C or Ada.

andai
Most safety-critical applications are written in C

This puzzles me — wasn’t safety one of the main reasons for developing alternatives to C and C++?

tim36272
You’re thinking of things like type safety, garbage collection, etc.

I’m talking about safety in terms of people dying. Things like garbage collection are the opposite of life safety: what if your airplane decided it needed to free up memory ten seconds from touchdown so it ran the garbage collector? What if running the garbage collector caused a valve to respond 0.1 seconds late to a command, which caused a chain reaction resulting in a hydraulic line bursting and losing control of the rudder?

C can be safe because it does exactly what the programmer tells it to do, nothing more and nothing less. There’s no magic going on behind the scenes which could have complex interactions with other behind the scenes magic.

A common example is C++’s std::vector. This container expands as needed to accommodate as many elements as you need. But you have a limited amount of memory on the system, so you need to do static analysis to determine the maximum size of that vector. And you need to be sure that you have enough memory for that plus everything else in your system.

We’ll now you’ve eliminated a lot of the convenience of using std::vector: you might as well just allocate that max size to it and avoid all the overhead std::vector imposes by growing in size.

The other main advantage of std::vector is templates. If you were to use a template in safety critical code you’d need to prove that the code generated by the compiler is correct for every template. We’ll now you’re diving down into all this auto-generated machine code: it would be easier to just write that code yourself and avoid the complexity introduced my the compiler’s template generator.

So, if we’ve eliminated all the usefulness of std::vector, why use it at all?

Repeat that process for most features in most languages and voila! You’re back at C 🙂

Developers Discuss Pros and Cons of Programming Languages – Slashdot

Linus Torvalds Says Rust Closer for Linux Kernel Development, Calls C++ ‘A Crap Language’

Asked about a suggestion by a commenter on the Linux Weekly News website, who said, during a discussion on the Google post, “The solution here is simple: just use C++ instead of Rust”, Torvalds could not restrain himself from chortling. “LOL,” was his response. “C++ solves _none_ of the C issues, and only makes things worse. It really is a crap language.

“For people who don’t like C, go to a language that actually offers you something worthwhile. Like languages with memory safety and [which] can avoid some of the dangers of C, or languages that have internal GC [garbage collection] support and make memory management easier. C++ solves all the wrong problems, and anybody who says ‘rewrite the kernel in C++’ is too ignorant to even know that.”

——
“There is a class of programmer that “clicks” with the OOP concepts of inversion of control, dependency injection, and always coding to an interface. This approach feels so correct to them that they become almost religious in their devotion to it. They believe it is the one-size-fits-all solution to every programming problem, and consider anyone who disagrees with them to simply be less intelligent than themselves (because no rational person could possibly disagree).

I have worked with such people. They quadruple the codebase, significantly increase development time, and introduce more bugs by doing so, all the while insisting that this will make the code easier to maintain in the long run. But it actually doesn’t; it just means that there is that much more code that must be refactored as new features come along.

They point at the ease with which layers can now be swapped-out as a total win. But in practice 90% of the interfaces have only one implementation. There is nothing to switch anything to because there just isn’t any need. And future development isn’t simplified by finding just the right layer to adjust; the changes are almost always cross-cutting so you have to refactor all those interfaces and layers top-to-bottom, each time, to get things working.

It just doesn’t work out in practice the way they insist it will. At least, not often.”

——
“Just use JavaScript, make the kernel run off node.js.”

Slashdot