this post was submitted on 16 Mar 2025
804 points (100.0% liked)

Programmer Humor

21852 readers
1100 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
804
C++ (ani.social)
submitted 1 week ago* (last edited 1 week ago) by [email protected] to c/[email protected]
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 96 points 1 week ago (2 children)

Except that many other languages have proven that C++ is simply terrible at providing meaningful errors.

[–] [email protected] 6 points 1 week ago (1 children)

I wish there was something like that for SQL

[–] [email protected] 9 points 1 week ago (2 children)

We can always make a Rust Query Language

[–] [email protected] 2 points 6 days ago

Behold: PRQL. I only know it exists not if the errors are good, my SQL needs are simple, but perhaps for some complex data wrangling it could be nicer idk

[–] [email protected] 8 points 1 week ago

Feels like some arcane divination magic, I WANT IT

[–] [email protected] 4 points 1 week ago* (last edited 1 week ago) (2 children)

The whole point of a segfault is that you can’t really know anything about it. Even in rust, when you get a segfault there is no meaningful error.

[–] [email protected] 12 points 1 week ago (1 children)

point is, Rust manages to give you not a segfault but a meaningful error almost all the time until you use unsafe

[–] [email protected] 3 points 1 week ago (1 children)

If you’re getting a segfault in C++, it’s also cause you used unsafe code. It’s just not officially enclosed in an “unsafe” block.

[–] [email protected] 7 points 1 week ago* (last edited 1 week ago)

the point was not on the unsafe word, but a very specific feature of Rust that helps enclosing unsafe code where the compiler wouldn't be able to 100% verify your logic. no such thing in C++. C++ does not even attempt to verify safety

your response is basically "get better at coding dumbass, I am the safety validator"

[–] [email protected] 5 points 1 week ago (1 children)

The worst thing you can do in non-unsafe Rust is perform an out-of-bounds indexing operation, or anything else that panics. The error you get tells you the panic's exact location in the source code, down to the line and column. Meanwhile, C and C++ either don't produce an error at all when accessing uninitialized memory (which is arguably the worst behavior), or it segfaults with zero extra info.

The only way to make Rust segfault is by performing unsafe operations, and those must always be clearly marked.

[–] [email protected] 4 points 6 days ago* (last edited 6 days ago) (1 children)

The only way to make Rust segfault is by performing unsafe operations.

Challange accepted. The following Rust code technically segfaults:

fn stackover(a : i64) -> i64 {
    return stackover(a);
}


fn main() {
    println!("{}", stackover(100));
}

A stack overflow is technically a segmentation violation. At least on linux the program recives the SIGSEGV signal. This compiles and I am no rust dev but this does not use unsafe code, right?

While the compiler shows a warning, the error message the program prints when run is not very helpfull IMHO:

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
[1]    45211 IOT instruction (core dumped)  ../target/debug/rust

Edit: Even the compiler warning can be tricked by making it do recusion in pairs:

fn stackover_a(a : i64) -> i64 {
    return stackover_b(a);
}

fn stackover_b(a : i64) -> i64 {
    return stackover_a(a);
}

fn main() {
    println!("{}", stackover_a(100));
}
[–] [email protected] 3 points 6 days ago