News for hackers. Stuff that matters.
Re:The NSA advises move to memory-safe languages by DeathArrow on Tuesday December 12, 2023 @09:36AM (#38612645)
Isn't C++ with RAII reasonably safe? I tried to learn/like Rust but it's against how I use to think.

If no friendlier safe high speed programming language appears, I rather use C/C++ and trade safety for friendliness.

Re:The NSA advises move to memory-safe languages by woodruffw on Tuesday December 12, 2023 @09:50AM (#38612843)
RAII is great (especially as a developer’s aid), but I don’t think it’s had a huge effect on memory unsafety: it’s still very easy to UAF in a RAII-only codebase, thanks to all of the flexibility C++ allows in constructors and destructors (and unintuitive behavior in moved-out-of objects).

Rust is generally perceived as having many of the same developer kindnesses as C++, while having same-class performance. Learning it has a bit of a curve, but I found that it eventually clicked (I have a C and C++ professional background).

Re:The NSA advises move to memory-safe languages by zaphar on Tuesday December 12, 2023 @09:46AM (#38612791)
If you have no users then go for it. However if you do then you are doing those users a disservice by exposing them to unnecessary risk.

Maybe the risk is mitigated in other ways. Your software runs as a cli and not a service. It doesn't process outside input. It is run in an ironclad sandbox.

But honestly, if you think the way C++ with RAII want's you to then you should already be following the rules that Rust want's you to follow for the most part.

Re:The NSA advises move to memory-safe languages by binary132 on Tuesday December 12, 2023 @09:49AM (#38612840)
so what you’re saying is proper C++ is fine?
Re:The NSA advises move to memory-safe languages by zaphar on Tuesday December 12, 2023 @09:54AM (#38612908)
What I'm saying is that if you are sufficiently smart then you could concievably write perfectly safe C++. But since almost no one in practice has ever been able to be sufficiently smart consistently enough to ship C or C++ code that doesn't have memory safety issues, I don't trust anyone to do so and would rather people stop writing stuff in them when there are better languages to use where I don't have to trust you as much.
Re:The NSA advises move to memory-safe languages by binary132 on Sunday December 17, 2023 @10:24PM (#38678916)
Re:The NSA advises move to memory-safe languages by trealira on Tuesday December 12, 2023 @10:54AM (#38613834)
Modern C++ can still be unsafe. I recently wrote a comment about it here: https://news.ycombinator.com/item?id=38576681
Re:The NSA advises move to memory-safe languages by tobias12345 on Tuesday December 12, 2023 @10:08AM (#38613124)
RAII is great, but unfortunately it breaks down when the resource it manages leaks out of the RAII type.

E.g. Whenever handing out the raw pointer stored in a unique_ptr, the code receiving that raw pointer can delete it, which will very likely lead to a use after free and certainly to a double free issue.

Re:The NSA advises move to memory-safe languages by xdavidliu on Tuesday December 12, 2023 @10:19AM (#38613277)
I was shocked to learn that reaching an end of a function without returning is actually UB and the compiler doesn't stop you; only warns. For example:

```

class Foo;

Foo get_foo() { std::cout << "whoops, I forgot to return\n"; }

int main() { const auto foo = get_foo(); }

```

Re:The NSA advises move to memory-safe languages by jjgreen on Tuesday December 12, 2023 @11:52AM (#38614746)
(HN weak markdown, indent 2 spaces for code-block)
Re:The NSA advises move to memory-safe languages by xdavidliu on Saturday December 16, 2023 @10:32AM (#38664934)
noted for next time, thanks
Re:The NSA advises move to memory-safe languages by ryao on Tuesday December 12, 2023 @02:59PM (#38617565)
Serious C/C++ projects build with -Wall -Werror. The compiler definitely stops you then.