Live data from Hacker News

Should I choose Ada, SPARK, or Rust over C/C++? (2024)

blog.adacore.com

71–80 of 173 posts

Re: Should I choose Ada, SPARK, or Rust over C/C++? (2024)

#71

Their example of why Ada has better strong typing than Rust is that you can have floats for miles and floats for kilometers and not get them mixed up. News flash, Rust has newtype structs, and you can also do basically the same thing in C++. I don't know much about Ada. Is its type system any better than Rust's?

There is no elegant solution in Rust to make something like

  type Temperature_K is digits 6 range 0 .. ;

Re: Should I choose Ada, SPARK, or Rust over C/C++? (2024)

#72

Earlier quoted context omitted.

> These are subsets of their respective languages, but Pretty much every language has such a subset. Nothing new then, sigh...

C and C++ don't have such a subset. That seems pretty relevant, given they're the languages being compared and they're used for the majority of safety critical development. The standards I mentioned use tricks to get around this. MISRA, for example, has the infamous rule 1.3 that says "just don't do bad things". Actually following that or verifying compliance are problems left completely to the user. On the other han…

C and C++ don't have such subset defined as part of their standard. Left to users means left to additional tools, which do exist. Rust only has memory safety by default, this is a small part of the problem and it is not clear to me that having this helps with functional safety. (Although I agree that it helps elsewhere).

Re: Should I choose Ada, SPARK, or Rust over C/C++? (2024)

#73
post #66

Their example of why Ada has better strong typing than Rust is that you can have floats for miles and floats for kilometers and not get them mixed up. News flash, Rust has newtype structs, and you can also do basically the same thing in C++. I don't know much about Ada. Is its type system any better than Rust's?

Aside from technical factors, there are social factors involved. For example, both Python and C++ has operator overloading. But in C++ that's horrible and you run screaming from it, while in Python land it's perfectly fine. What is the difference? Culture and taste.

It isn't the same operator overloading.

In C++ operator overloading can easily mess with fundamental mechanisms, often intentionally; in Python it is usually no more dangerous than defining regular functions and usually employed purposefully for types that form nice algebraic structures.

Re: Should I choose Ada, SPARK, or Rust over C/C++? (2024)

#74

I know there is a belief that Rust/Ada etc is safer than C/C++ and in some cases that is true. I know of multiple, airworthy aircraft that are flying with C++ code. I also know of aircraft flying with Ada. The aircraft flying with Ada is hard to maintain. There is also a mountain of testing that goes into it that is not just unit testing. This mountain of integration, subsystem and system level testing is required re…

Firmware is a different story, but for controls code the proper and civilized way of working is using Simulink with something like Polyspace and Embedded Coder, and auto-gen verifiable C code from your model. I know that on HN vim + invoking CC is the only way of working, but industry began to move forward quite long ago.

Sadly, Mathworks have monopoly there.

Re: Should I choose Ada, SPARK, or Rust over C/C++? (2024)

#77
post #29

Earlier quoted context omitted.

Google had published a few papers stating that Rust code has fewer defects than similar complexity Go and Java services. It's not just memory safety, but the design of the type system and error handling semantics that enable it to be smooth with exceptional behavior.

Go's biggest flaw for backends is the error handling. No exceptions and nothing checking that you use the err. Java's issue might be the lack of cooperative multitasking until recently (virtual threads). Best you could do was those promises frameworks that mangle your code, and Google in particular uses something a hundred times worse called Guice (which is also DI).

Java's biggest problem is the fact that mutability is so baked into the language. I'm working on a project now where I always need to dig deep to find out if something has been mutated or not. Yes, there are records and we are now getting into data oriented programming. But older codebases are really hard to read.

Re: Should I choose Ada, SPARK, or Rust over C/C++? (2024)

#78

Earlier quoted context omitted.

Lean the math prover? What does that have to do with Ada/Rust?

> Lean the math prover? What does that have to do with Ada/Rust? I'm going to be rude, but there are 4 sentences in this thread and you appear to have not read two of them. The comment I responded to: >> I've never heard of SPARK. What advantages does it have compared to Lean ? [emphasis added] The "It" in my response refers to SPARK.

There was no need to be rude.

Re: Should I choose Ada, SPARK, or Rust over C/C++? (2024)

#80
post #11

Alternatively, just get better at C/C++… It isn’t going anywhere, and it feels like more developers are coming around to the idea that maybe security guarantees are not worth throwing the baby out with the bath water.

It’s a common misconception that the point of Rust is just security. Rust helps avoid a very broad class of bugs, that security bugs are only a subset of.

They'd simply tell you that by just magically "getting better" at C/C++, those would be resolved too. And if my grandmother had wheels, she'd have been a bike [0].

It's like a JRPG that may be a slog at the beginning, but then really gets going after the first 50-60 hours. Just gotta replace the hours with years, and huff even more glue.

And these are the people moaning about Rust and religious thinking... good old DARVO at it again, and it's growing more and more on the nose.

[0] https://youtu.be/A-RfHC91Ewc

Post reply on HN