this post was submitted on 08 Jun 2024
1040 points (98.5% liked)

Programmer Humor

18250 readers
1498 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 1 year ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] hark 88 points 3 weeks ago (3 children)

The graph goes up for me when I find my comfortable little subset of C++ but goes back down when I encounter other people's comfortable little subset of C++ or when I find/remember another footgun I didn't know/forgot about.

[–] LANIK2000 43 points 3 weeks ago* (last edited 3 weeks ago)

That's one thing that always shocks me. You can have two people writing C++ and have them both not understand what the other is writing. C++ has soo many random and contradictory design patterns, that two people can literally use it as if it were 2 separate languages.

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

When I became a team leader at my last job, my first priority was making a list of parts of the language we must never use because of our high reliability requirement.

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

Care to share any favourites?

[–] [email protected] 27 points 3 weeks ago (2 children)

strtok is a worst offender that comes to mind. Global state. Pretty much just waiting to bite you in the ass and it did, multiple times.

[–] [email protected] 13 points 3 weeks ago* (last edited 2 weeks ago) (1 children)

Sure, strtok is a terrible misfeature, a relic of ancient times, but it's plainly the heritage of C, not C++ (just like e.g. strcpy). The C++ problems are things like braced initialization list having different meaning depending on the set of available constructors, or the significantly non-zero cost of various abstractions, caused by strange backward-compatible limitations of the standard/ABI definitions, or the distinctness of vector<bool> etc.

load more comments (1 replies)
load more comments (1 replies)
[–] [email protected] 18 points 3 weeks ago (3 children)

my comfortable little subset of C++

I also have one. I call it "C"

[–] hark 5 points 3 weeks ago (1 children)

C is almost the perfect subset for me, but then I miss templates (almost exclusively for defining generic data structures) and automatic cleanup. That's why I'm so interested in Zig with its comptime and defer features.

load more comments (1 replies)
load more comments (2 replies)
[–] [email protected] 78 points 3 weeks ago (7 children)

This graph cuts off early. Once you learn that pointers are a trap for noobs that you should avoid outside really specific circumstances the line crosses zero and goes back into normal land.

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

C++ is unironically my favorite language, especially coding in python feels so ambiguous and you need to take care of so many special cases that just wouldn't even exist in C++.

[–] GlitchyDigiBun 57 points 3 weeks ago (4 children)

But can you read someone else's C++ code?

[–] [email protected] 46 points 3 weeks ago

Why should I do that?

[–] Narwhalrus 28 points 3 weeks ago (2 children)

Typically, I can read an "average" open source programmers code. One of the issues I have with C++ is the standard library source seems to be completely incomprehensible.

I recently started learning rust, and the idea of being able to look at the standard library source to understand something without having to travel through 10 layers of abstraction was incredible to me.

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

One of the issues I have with C++ is the standard library source seems to be completely incomprehensible.

AAAAAAhhh I once read a Stroustrup quote essentially going "if you understand vectors you understand C++", thought about that for a second, coming to the conclusion "surely he didn't mean using them, but implementing them", then had a quick google, people said llvm's libc++ was clean, had a look, and noped out of that abomination instantly. For comparison, Rust's vectors. About the same LOC, yes, but the Rust is like 80% docs and comments.

load more comments (1 replies)
[–] [email protected] 5 points 3 weeks ago

I wonder what went into their minds when they decided on coding conventions for C++ standard library. Like, what’s up with that weird ass indentation scheme?

[–] [email protected] 11 points 3 weeks ago

You can absolutely read my code. The ability (similar to functional languages) to override operators like crazy can create extremely expressive code - making everything an operator is another noob trap... but using the feature sparingly is extremely powerful.

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

Your graph also cuts out early. Eventually you want to get performance gains with multi-threading and concurrency, and then the line drops all the way into hell.

[–] [email protected] 17 points 3 weeks ago (3 children)

Good Afternoon Sir, have you heard about our lord and savior pthreads?

[–] [email protected] 27 points 3 weeks ago* (last edited 3 weeks ago) (5 children)

I'm not saying you can't do multi-threading or concurrency in C++. The problem is that it's far too easy to get data races or deadlocks by making subtle syntactical mistakes that the compiler doesn't catch. pthreads does nothing to help with that.

If you don't need to share any data across threads then sure, everything is easy, but I've never seen such a simple use case in my entire professional career.

All these people talking about "C++ is easy, just don't use pointers!" must be writing the easiest applications of all time and also producing code that's so inefficient they'd probably get performance gains by switching to Python.

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

That's the problem of most general-use languages out there, including "safe" ones like Java or Go. They all require manual synchronization for shared mutable state.

[–] [email protected] 20 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

There's a difference between "You have to decide when to synchronize your state" and "If you make any very small mistake that appears to be perfectly fine in the absence of extremely rigorous scrutiny then this code block will cause a crash or some other incomprehensible undefined behavior 1/10000 times that it gets run, leaving you with no indication of what went wrong or where the problem is."

load more comments (1 replies)
load more comments (4 replies)
load more comments (2 replies)
[–] [email protected] 15 points 3 weeks ago (2 children)

First year programming in the late 90s .. segmentation fault? I put printfs everywhere. Heh. You'd still get faults before the prints happened, such a pain to debug while learning. Though we weren't really taught your point of the comment at the time.

Least that was my experience on an AIX system not sure if that was general or not, the crash before a print I mean.

[–] [email protected] 9 points 3 weeks ago

Yea, pointer arithmetic is cute but at this point the compiler can do it better - just type everything correctly and use []... and, whenever possible, pass by reference!

load more comments (1 replies)
[–] [email protected] 15 points 3 weeks ago (8 children)

I've been using C++ almost daily for the past 7 years and I haven't found a use for shared_ptr, unique_ptr, etc. At what point does one stop being a noob?

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

Given that you probably are using pointers, and occasionally you are allocating memory, smart pointers handle deallocation for you. And yes, you can do it yourself but it is prone to errors and maybe sometimes you forget a case and memory doesn't get deallocated and suddenly there is a leak in the program.

When you're there, shared_ptr is used when you want to store the pointer in multiple locations, unique_ptr when you only want to have one instance of the pointer (you can move it around though).

Smart pointers are really really nice, I do recommend getting used to them (and all other features from c++11 forward).

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

Smart pointers are really really nice, I do recommend getting used to them (and all other features from c++11 forward).

You’re recommending him to give up his sanity and/or life?

load more comments (1 replies)
[–] riodoro1 9 points 3 weeks ago (3 children)

This guy probably still uses a char*.

What have you been using it daily for? arduino development? I’m hoping no company still lives in pre C++17 middle ages.

[–] [email protected] 7 points 3 weeks ago

My company still uses c90. I just want to for(uint8 i = 0;;) 🥹

load more comments (2 replies)
[–] [email protected] 8 points 3 weeks ago

At what point does one stop being a noob?

I recognize that trick question. For C++, the answer is always "soon".

[–] [email protected] 7 points 3 weeks ago (2 children)

well, if I have an object on the heap and I want a lot of things to use it at the same time, a shared_ptr is the first thing I reach for. If I have an object on the heap and I want to enforce that no one else but the current scope can use it, I always reach for a unique_ptr. Of course, I know you know all of this, you have used it almost daily for 7 years.

In my vision, I could use a raw pointer, but I would have to worry about the lifetime of every object that uses it and make sure that it is safe. I would rather be safe that those bugs probably won't happen, and focus my thinking time on fixing other bugs. Not to mention that when using raw pointers the code might get more confusing, when I rather explicitly specify what I want the object lifetime to be just by using a smart pointer.

Of course, I don't really care how you code your stuff, if you are comfortable in it. Though I am interested in your point of view in this. I don't think I've come across many people that actually prefer using raw pointer on modern C++.

load more comments (2 replies)
load more comments (4 replies)
[–] WormFood 6 points 3 weeks ago

pointers are fine, but when you learn about the preprocessor and templates and 75% of the STL it goes negative again

c++ templates are such a busted implementation of generics that if I didn't have context I'd assume they were bad on purpose like malbolge

load more comments (2 replies)
[–] [email protected] 46 points 3 weeks ago (7 children)

Hot take, C is better then C++. It really just has one unique footgun, pointers, which can be avoided most of the time. C++ has lots of (smart)pointer related footguns, each with their own rules.

[–] Valmond 17 points 3 weeks ago (3 children)

If you do C, and avoid pointers, do tell me what the point is using the language at all?

I mean if memory management is "the only way to shoot yourself in the foot" in C, then thats a quite big part of the language!

load more comments (3 replies)
[–] [email protected] 12 points 3 weeks ago

Then C++ what?

[–] [email protected] 11 points 3 weeks ago

Yeah. My journey of love, loathing, hatred, adoration, and mild appreciation for C++, ended with the realization that 90% of the time I can get the job done in C with little hassle, and a consistent, predictable, trustworthy set of unholy abominations.

[–] AProfessional 8 points 3 weeks ago

C++ literally makes it easier to avoid raw pointers and allocation that are dangerous…

[–] jas0n 5 points 3 weeks ago* (last edited 3 weeks ago) (6 children)

Preach brother, I don't think that's a hot take at all. I've become almost twice as productive since moving from c++ to c. I think I made the change when I was looking into virtual destructors and I was thinking, "at what point am I solving a problem the language is creating?" Another good example of this is move semantics. It's only a solution to a problem the language invented.

My hot take: The general fear of pointers needs to die.

load more comments (6 replies)
load more comments (2 replies)
[–] ninth_plane 41 points 3 weeks ago (2 children)

Eventually the line comes back in from the top.

[–] [email protected] 15 points 3 weeks ago

Or perhaps it will come from the right? Undefined behaviour is the magic word

[–] RoyaltyInTraining 13 points 3 weeks ago

Integer underflow

[–] erp 32 points 3 weeks ago

C++: C with blackjack and 40 year old hookers. Anyway, only the rich can inherit diamonds or something. Or perhaps not, my memory is corrupted. I'm open to any pointers though...

[–] [email protected] 31 points 3 weeks ago (3 children)

Compared to Assembly language, C++ is fantastic! :-P

[–] scrion 26 points 3 weeks ago (1 children)

It's actually a lot worse than ASM, there are far more ambiguities in C++. And yet here I am, still developing with it some 30+ years later.

Don't worry, I'm using Rust were it makes sense.

load more comments (1 replies)
[–] GlitchyDigiBun 15 points 3 weeks ago (4 children)

Just got a Commodore 64 and been having fun with ASM. I'm also weird. Don't be like me.

[–] [email protected] 10 points 3 weeks ago

Assembly was my first language after BASIC - I know I'm weird, and I'm okay with that:-). Tbf it was for a calculator, so simplified. Any language ofc can go off the deep end in terms of complexity, or if you stick to the shallows it can be fairly simple to write a hello world program (though it took me a month to successfully do that for my calculator, learning on my own and with limited time spent on that task:-).

load more comments (3 replies)
[–] [email protected] 16 points 3 weeks ago (4 children)

I like C# better. Ok, I'll see myself out.

load more comments (4 replies)
[–] TangledHyphae 11 points 3 weeks ago

As someone who writes C++ every day for work, up to version C++20 now, I hate the incoming C++23 even more somehow. The idea of concepts, it just... gets worse and worse. Although structured binding in C++17 did actually help some with the syntax, to be fair.

load more comments
view more: next ›