419
average c++ dev (programming.dev)

I don't think that casting a range of bits as some other arbitrary type "is a bug nobody sees coming".

C++ compilers also warn you that this is likely an issue and will fail to compile if configured to do so. But it will let you do it if you really want to.

That's why I love C++

you are viewing a single comment's thread
view the rest of the comments
[-] LodeMike@lemmy.today 8 points 1 week ago

People just think that applying arbitrary rules somehow makes software magically more secure, like with rust, as if the compiler won't just "let you" do the exact same fucking thing if you type the unsafe keyword

[-] BatmanAoD@programming.dev 25 points 1 week ago

It's neither arbitrary nor magic; it's math. And unsafe doesn't disable the type system, it just lets you dereference raw pointers.

[-] Speiser0@feddit.org 12 points 1 week ago

You don't even need unsafe, you can just take user input and execute it in a shell and rust will let you do it. Totally insecure!

[-] ignotum@lemmy.world 14 points 1 week ago

Rust isn't memory safe because you can invoke another program that isn't memory safe?

[-] Speiser0@feddit.org 8 points 1 week ago

My comment is sarcastic, obviously. The argument Kairos gave is similar to this. You can still introduce vulnerabilities. The issue is normally that you introduce them accidentally. Rust gives you safety, but does not put your code into a sandbox. It looked to me like they weren't aware of this difference.

[-] Ajen@sh.itjust.works 4 points 1 week ago

You don't need unsafe to write vulnerable code in rust.

https://github.com/Speykious/cve-rs

[-] LodeMike@lemmy.today 1 points 1 week ago

Yes I know there are other ways to do it. That's one way.

[-] panda_abyss@lemmy.ca 2 points 1 week ago

I don't know rust, but for example in Swift the type system can make things way more difficult.

Before they added macros if you wanted to write ORM code on a SQL database it was brutal, and if you need to go into raw buffers it's generally easier to just write C/objc code and a bridging header. The type system can make it harder to reason about performance too because you lose some visibility in what actually gets compiled.

The Swift type system has improved, but I've spent a lot of time fighting with it. I just try to avoid generics and type erasure now.

I've had similar experiences with Java and Scala.

That's what I mean about it being nice to drop out of setting up some type hierarchy and interfaces and just working with a raw buffers or function pointers.

this post was submitted on 22 Jul 2025
419 points (100.0% liked)

Programmer Humor

25471 readers
1135 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS