this post was submitted on 16 Mar 2025
790 points (98.2% liked)

Programmer Humor

21706 readers
480 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
790
C++ (ani.social)
submitted 4 days ago* (last edited 4 days ago) by kiri@ani.social to c/programmer_humor@programming.dev
 
you are viewing a single comment's thread
view the rest of the comments
[–] riodoro1@lemmy.world 84 points 4 days ago (3 children)

Am I bad at programming?

No, it’s the language thats wrong.

[–] RoyaltyInTraining@lemmy.world 94 points 4 days ago (2 children)

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

[–] QuazarOmega@lemy.lol 6 points 4 days ago (1 children)

I wish there was something like that for SQL

[–] rickyrigatoni@lemm.ee 7 points 4 days ago (2 children)

We can always make a Rust Query Language

[–] PartiallyApplied@lemmy.world 2 points 2 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

[–] QuazarOmega@lemy.lol 8 points 4 days ago

Feels like some arcane divination magic, I WANT IT

[–] SorryQuick@lemmy.ca 1 points 4 days ago* (last edited 4 days 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.

[–] WhyJiffie@sh.itjust.works 8 points 3 days 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

[–] SorryQuick@lemmy.ca -2 points 3 days 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.

[–] WhyJiffie@sh.itjust.works 5 points 3 days ago* (last edited 3 days 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"

[–] RoyaltyInTraining@lemmy.world 4 points 3 days 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.

[–] weker01@sh.itjust.works 2 points 2 days ago* (last edited 2 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));
}
[–] asdfasdfasdf@lemmy.world 21 points 4 days ago (1 children)

I mean, this is correct in many cases, unironically.

It should be one of the core purposes of a programming language to help humans to write the code they intend. If a language doesnt do that then it's bad.

[–] Shanmugha@lemmy.world 1 points 2 days ago* (last edited 2 days ago) (1 children)

I tend to disagree. The language should allow me to do things, and what is simple and obvious logically should be simple and obvious in the language (I am looking at you, JavaScript with [] != [])

What I intend - well, more than half my work is figuring out what I intend, language should have no say in this, save things like "we do this kind of trick like this here" (for example, C++ has no concept of "interface" entity. Ok, looks like I can use virtual class instead)

It is when languages start trying to be "helpful" they become an ugly mess: meaningful white spaces in Python? The whole shit with prototypes and objects in JS(see above)? Fuck this shit, I am not going to call those two good programming languages

[–] asdfasdfasdf@lemmy.world 3 points 2 days ago* (last edited 2 days ago) (1 children)

I think you're saying the same thing as what I am. If it's more complex than what you may think, the language should guard against it. If not, it should make it simple.

Rust, for example, is the only mainstream language where it isn't possible to read from a file handle after it's been closed. Doing so is a compilation failure. This is just a general invariant of "how to use files".

But you also don't need to think about allocating or deallocating memory in Rust. It does that fke you automatically, even though it's not GC.

JS can also be complicated when it tries to hide realities about the world. E.g. is a const array or object immutable? No, the pointer is. But pointers don't exist! /s

[–] Shanmugha@lemmy.world 1 points 2 days ago (1 children)

Looks like we still differ. If something is more complicated than what I may think, then there are some possibilities:

  • I have not learned to language properly yet (this is where I stand with C++, so no matter how many times I've got segfaults, now is not the time for me to say language is bad)
  • I have chosen the wrong tool (writing a videoplayer in assembler? something went way wrong here)
  • tool is actually bad (my rant above goes here. in the sake of making some things easy and simple, something basic in the language got screwed up irrevocably)

And if I managed to try reading from a closed handle, or to access a memory that I am not actually allowed to use, or... (could not get more examples out of the top of my head), it is not the job of the language to slap my hands, as long as I follow the syntax. Most of the time (if not all the time) this means I have not accounted for something that my code allowed to happen - so my responsibility to deal with that

What I keep hearing about Rust is still in the lines of too-much-fucking-care (that's besides obviously dumb rule of "no more than one owner of a variable at any moment" which then had to be worked around because not everything can be done this way. please correct me if I am wrong here)

[–] asdfasdfasdf@lemmy.world 2 points 2 days ago (1 children)

Yep, we disagree. The world and technology especially is an extremely complicated place. IMO any complex system that is built upon "humans should just know all this complexity and keep it in mind all the time" is fundamentally broken.

[–] Shanmugha@lemmy.world 1 points 2 days ago* (last edited 2 days ago)

It depends. We may have our differences in weighing things, but yes, complexity of the system must correlate with complexity of the task it is used for. A system allowing to do things without any complexity means either no complex things to be done or straight up magic

[–] pimento64@sopuli.xyz 17 points 4 days ago (1 children)

Valid languages:

  1. HolyC

That's it

[–] ICastFist@programming.dev 5 points 4 days ago

Brainfuck has entered the chat