Live data from Hacker News

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

blog.adacore.com

131–140 of 173 posts

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

#131
post #90

Earlier quoted context omitted.

Though if you do that km times km isn't km it is a volume - so your custom type would be wrong to have all operations. what unit km times km should be isn't clear.

I guess I should have said `unique_type >` then :) Then you can do the same as std::chrono::duration does.

Now write a book on the various tradeoffs from that decision. there is no perfect general answer, some domains have specific needs that are different. Depending on your domain that might be a good choice or it might be terrible

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

#132
post #90

Earlier quoted context omitted.

In C++ you probably could even make a templated class that implements all possible operators for any type that supports it with concepts. Then you can just `using kilometer = unique_type ` without needing to create a custom type each time.

Though if you do that km times km isn't km it is a volume - so your custom type would be wrong to have all operations. what unit km times km should be isn't clear.

who said `operator*` needs to return the same type as its parameters?

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

#133
post #72

Earlier quoted context omitted.

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).

If you think a strong and convenient type system helps with functional safety, then Rust helps with functional safety. This is also generally the experience in the industry.

I am not convinced a strong type system helps with functional safety and I am not even deeply impressed by Rust's type system. The scientific literature does even seem even that clear about whether a strong type system substantially reduces software defects in general. I believe in proofs though. I generally believe complexity is bad and both C++ and Rust are too complex for my taste. I also think Rust has severe supply chain issues.

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

#134
post #89

Earlier quoted context omitted.

There is no elegant solution in Rust to make something like type Temperature_K is digits 6 range 0 .. ;

at least that is an unsigned (though there are no usigned hardware floats). If you said tempemerature C there you range starts at -273.15 and you want errors of some sort to happen if you go below that.

Ideally, the program would freeze

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

#135
post #44

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?

I'm super interested how you can do this in C++. Say, I need aggregate struct with a few 16 and 32 bit fields, some are little endian and some big endian. I do not want C++ to let me mix up endianness. How do I do it?

There's several libraries, including some supporting units and mathematical operations yielding the correct result types.

And as usual, it mostly comes with zero overhead, beyond optional runtime range checking and unit conversions.

But C++ is a meta-programming language. Making up your own types with full operator overloading and implicit and explicit conversions is rather easy.

And the ADA feature of automatically selecting a suitable type under the hood isn't actually that useful, since computers don't really handle that many basic types on a hardware level. (And just to be clear, C++ templates can do the same either way)

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

#136
I remember hearing on a stream, and I find it to be true, that Rusts major innovation over Haskell, another boilerplate heavy language if your goal is systems programming, is that instead of "purity" which any sane programmer would just discard as useless right way they innovate "saftey" as a propaganda word, as a moral failing of the programmer for ignoring what is quite clearly useless.

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

#138
post #90

Earlier quoted context omitted.

In C++ you probably could even make a templated class that implements all possible operators for any type that supports it with concepts. Then you can just `using kilometer = unique_type ` without needing to create a custom type each time.

Though if you do that km times km isn't km it is a volume - so your custom type would be wrong to have all operations. what unit km times km should be isn't clear.

These libraries already exist. God how people underestimate C++ all the time.

Of course you can use a unit type that handles conversions AND mathematical operations. Feet to meter cubed and you get m³, and the library will throw a compile error if you try to assign it to anything it doesn't work with (liters would be fine, for example)

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

#139
post #28

Personally I think Swift can be a good choice that is more familiar to existing C++ developers than the others, and a lot of people seem to be sleeping on it. It has full native interop with C and C++ so you can already use all your existing libraries. Historically it lacked cross-platform support but this is not true anymore. It does lack a native GUI framework, but for now you can keep using C++ ones. Some people c…

Swift, while being slightly more friendly for extreme beginners than rust, is just so kneecapped and bloated that it has the opposite problem as rust. At some moderate level of competence it actively hinders learning. All of the weird closure and multithreading syntax is more harmful than good. Whereas Rust has a high floor and somewhat infuriating borrow checking, once you figure your way out of them you’ve actually…

Swift syntax did feel overly fancy to me too. Look at how complicated and version-dependent the StackOverflow Swift answers are for conceptually simple things.

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

#140
post #25

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?

This was posted to about a day ago: https://github.com/johnperry-math/AoC2023/blob/master/More_D... But a noteworthy excerpt: ``` Ada programs tend to define types of the problem to be solved. The compiler then adapts the low-level type to match what is requested. Rust programs tend to rely on low-level types. That may not be clear, so two examples may help: Ada programmers prefer to specify integer types in terms of…

You can use TiVec to index with something other than usize. https://crates.io/crates/typed-index-collections
Post reply on HN