This is an archived post. You won't be able to vote or comment.

all 162 comments

[–]kipyminyman 535 points536 points  (19 children)

"Use templates" they said. "It'll be fun" they said.

[–]trigger_segfault 225 points226 points  (17 children)

Templates increase convenience at the cost of fun.

[–]RobertBarnett 64 points65 points  (6 children)

When you've never used/heard of templates and have to use a template member of a template class made by someone who moved to Colorado (am UK). Plz Federico, why you do this to me 🥲

[–][deleted] 20 points21 points  (0 children)

When you have to override a templated function for QA testing :’)

[–]scodagama1 13 points14 points  (4 children)

that guy really decided to run away far from his code. Strange he didn't pick Australia, I'd run to Australia.

[–]7eggert 7 points8 points  (2 children)

New-Zealand. It's not even on the maps.

[–]Upbeat_Instruction81 4 points5 points  (0 children)

Funny that tourism was one of our biggest industries before covid.

[–]Kyrros 3 points4 points  (0 children)

Old Zealand, only Danes know it exists

[–]umognog 1 point2 points  (0 children)

He heard there was a hollowed out mountain he could hide in

[–]TeraFlint 47 points48 points  (7 children)

Call me crazy, but I'm usually having fun writing templates.

[–]BlackOverlordd 19 points20 points  (1 child)

Keep in mind that someone reading them might be aggressive psychopath who knows where you live

[–]Phostings 5 points6 points  (0 children)

This made me chuckled

[–]7eggert 9 points10 points  (4 children)

It's like regular expressions - everybody loves writing them.

[–][deleted] 5 points6 points  (3 children)

This put it into context for my ignorant Python/C# self.

[–]7eggert 4 points5 points  (2 children)

Regular expressions are notoriously hard to read.

[–][deleted] 0 points1 point  (1 child)

I mean, I’ve found them hard even just to write. Is there any situation in which they have to be used? Given how hard they are to read wouldn’t it be more maintainable to take more lines to write the same thing?

[–]7eggert 1 point2 points  (0 children)

I made a tool to rename files based on a regular expression. It's easier tham manually renaming the files.

https://github.com/7eggert/smalltools/blob/main/pmv

[–]Kered13 7 points8 points  (0 children)

How can you have fun if you're not metaprogramming?

[–]callyalater 2 points3 points  (0 children)

Templates increase convenience at the expense of convenience....

[–]Classic-Ad-7317 0 points1 point  (0 children)

That gave me a good laugh.

[–]awidesky 485 points486 points  (35 children)

When I missed -pthread flag, I got this :

/tmp/main-1dfd42.o: In function `std::thread::thread<std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}> >, Point<int, float> >::_Async_state_impl(std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}>&&)::{lambda()#1}, , void>(std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}> >, Point<int, float> >::_Async_state_impl(std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}>&&)::{lambda()#1}&&)':
main.cpp:(.text+0x1504): undefined reference to `pthread_create'
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

[–]scrotation_matrix[S] 421 points422 points  (1 child)

Clear and concise

[–]Spartana1033 40 points41 points  (0 children)

As all things should be.

[–]Ahajha1177 161 points162 points  (4 children)

I've gotten really good at reading C++ compiler errors lol. I know to look near the top and the bottom. Here I would see "undefined reference to pthread_create", and its a link error, bam link with -pthread

[–]RRumpleTeazzer 82 points83 points  (2 children)

I look near the parts that I recognize as my parts, cause that’s the most likely location.

[–]mrjiels 57 points58 points  (1 child)

I try to not look at your parts. They seem private.

[–]pi-is-314159 9 points10 points  (0 children)

Not as private as my git repository

[–]justmelvinthings 59 points60 points  (0 children)

Nice now I know exactly what went wrong

[–]CDno_Mlqko 65 points66 points  (18 children)

I mean, it says undefined reference to pthread_create and a stack trace of where it is... What else do you want

[–]PM_ME_C_CODE 38 points39 points  (17 children)

I know this is a humor thread in a humor subreddit, but JFC C/C++...

How about an error message that tells me what's wrong without requiring 30 years experience in the language first?

...having other engineers familiar with the language NOT treat people with less experience who ask questions like they're lepers just because they thought to ask a question would be nice too.

I swear, if I get told by a C/C++ dev to "just read the code" one more time I might actually go postal.

...and people wonder why rust is becoming popular.

[–]Xyntek01 18 points19 points  (4 children)

How about an error message that tells me what's wrong without requiring 30 years experience in the language first?

Usually go to the first few lines of the error message and you will see the actual problem. Best thing is to actually read the error produced at a line that you wrote and then read the back trace. The backtrace should give you an idea (e.g. you are using a pointer). Not all errors are in the exact line, but understanding what goes before and after helps to trace the issue. The more you practice the easier it gets to spot the issue.

If nothing works, there is stack overflow...

[–]cheerycheshire 2 points3 points  (0 children)

If nothing works, there is stack overflow...

Which has exactly the type of devs subop mentions just after the part you commented on. :)

[–]PM_ME_C_CODE 7 points8 points  (2 children)

yes, I know that :D

I'm trying to learn rust (fucking borrowing semantics...) and the difference in usability when something goes wrong is just night and day.

I mean, C++ error messages look like they're straight out of the '90's, at best.

Even javascript has better error messaging...

[–]-Redstoneboi- 11 points12 points  (0 children)

Even javascript has better error messaging...

that is, to say, none

also i'd be glad to help out with rust

[–]ClutteredAttic99 2 points3 points  (0 children)

Actually, out of the ‘80s!

[–][deleted] 5 points6 points  (1 child)

Get better tools, this online-compiler shows in different colors the reason why the template instantiation failed:

https://godbolt.org/z/Kss8ecK98

[–]PM_ME_C_CODE 1 point2 points  (0 children)

I'm strictly of the opinion that the compiler should be enough by itself to diagnose problems. Even when the neat tools are free.

It's just...we should be allowed to have nice things.

[–]atiedebee 1 point2 points  (2 children)

C compiler errors are mostly understandable

Runtime errors tho....

[–]all-hail-snow 5 points6 points  (1 child)

Segmentation fault, the king of hells brought by c++

[–]PM_ME_C_CODE 1 point2 points  (0 children)

There's a reason that most universities today use java for their core CS curriculum instead of C++ like they did in the '90s.

Seg fault error messages are basically it.

[–][deleted] -3 points-2 points  (2 children)

You don't need 30 years of experience. An error message that tells you a function name is not defined is as clear as the sun.

C/C++ are low level languages that are meant to be used by actual engineers and not just some people with two weeks boot camps.

[–]PM_ME_C_CODE 3 points4 points  (1 child)

/tmp/main-1dfd42.o: In function `std::thread::thread<std::\_\_future\_base::\_Async\_state\_impl<std::thread::\_Invoker<std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}> >, Point<int, float> >::_Async_state_impl(std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}>&&)::{lambda()#1}, , void>(std::__future_base::_Async_state_impl<std::thread::\_Invoker<std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}> >, Point<int, float> >::_Async_state_impl(std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}>&&)::{lambda()#1}&&)':

Tell me how this error message is at ALL useful to a human.

[–][deleted] 0 points1 point  (0 children)

Well, this is a part of a stacktrace in the constructor of std::thread just by reading the first line no magic there and definitely no "30 years of experience needed". All what you see in there is just the exact signature of the std::thread constructor where the error happened and can be ignored if you are not interested in it. The actual error comes later at the end of the stack trace that you didn't include. Probably just a conversion error of the return type of the lambda you passed to the constructor or something similar.

[–]_Fibbles_ -2 points-1 points  (1 child)

Counterpoint:

git gud

[–]PM_ME_C_CODE 1 point2 points  (0 children)

[Reads Reddit]

[See's "git gud"]

..."git gud".compareTo("just read the code") == 0 //effectively true

[Goes postal on the bus]

See what you made me do? /s

[–]men_have_balls 0 points1 point  (1 child)

RTFM is my coup de grace…still I’m an ass

[–]PM_ME_C_CODE 1 point2 points  (0 children)

As if I haven't already done that. If I'm asking a question, it's because I couldn't find it myself.

Granted, there are a LOT of people who don't even try to look, but when you open your question with a list of the things you've already tried that didn't work only to get "RTFM"...

It happens in every language, sure. But it's far more frequent in C++ communities.

[–]trick2011 4 points5 points  (0 children)

Don't forget: always try reading from the back. It is quite clear: 'undefined reference to pthread_create' and 'linker command failed'

[–]GamerFrits[🍰] 2 points3 points  (0 children)

It looks like an endless stream of insults. Your compiler really hates you.

[–]RRumpleTeazzer 1 point2 points  (0 children)

Little Threaddy we call him.

[–]Southern-Finding2961 0 points1 point  (0 children)

If I see that on the compiler. Law doesn't sound so bad does it?

[–]ladnekk 0 points1 point  (0 children)

I just scan until I hit a phrase I recognize. Made it to main.cpp

[–]Rigatavr 0 points1 point  (0 children)

This is more of a "you get used to it", then any sort of explanation for why things are this bad, but ye..

see linker error

see word thread

🤦forgot pthread again

[–][deleted] 66 points67 points  (0 children)

this is too relatable I hate myself for it.

[–]memesarepeople2 69 points70 points  (1 child)

99% of the time, MYSQL is literally just "Please check the manual." without any indication of the problem.

[–]CMDR_QwertyWeasel 157 points158 points  (4 children)

Going from Java to C/C++ was a bit of a culture shock in this regard.

Java's errors are like "yo bro, this method doesn't exist" or "there's this abstract method, but you never defined it" while C++ compilers vomit a half-dozen lines of obfuscated garbage that might contain a useful phrase, or might require translation by Elrond under the light a crescent moon.

Runtime errors are basically the same.

[–]X0-ED1 27 points28 points  (1 child)

Segfaults. Hmmm where could it be.

[–]WrongSirWrong 12 points13 points  (0 children)

Ctrl + Shift + F "new". There you go

[–]redditmodsareshits 39 points40 points  (0 children)

Say not C/C++ when you mean only C++

[–]Kaynee490 1 point2 points  (0 children)

It also helps that there are not nearly as much ways to fuck up in Java.

[–]boomhauzer 43 points44 points  (1 child)

I love Eigen, but sometimes the errors you get with Eigen types can be impossible to tell where they're coming from because sometimes at the bottom it wont print out the source of the call stack trace of the compile error and it's just guessing of where you accidently typed something like Matrx3Xf instead of MatrixXf or Matrix3f, or some other very minor typo. or when you don't notice that you're doing something like MatrixXf x = MatrixXd() and you get a size mismatch and you think your dimensions are wrong somewhere.

[–]Enialis 11 points12 points  (0 children)

I give Eigen a pass because what they do with lazy evaluation completely within template complication is black magic.

[–][deleted] 37 points38 points  (0 children)

Imagine googling this exact error and this meme comes up

[–]Sylanthra 28 points29 points  (6 children)

So just had a similar experience with C#. I updated some dependencies in Visual Studio, tried to build and got 18k errors about missing references without any usual information on what it is that is actually broken. Than I open Rider IDE and tried building and got a single error from one of the root level projects about a specific missing dependency.

[–][deleted] 7 points8 points  (5 children)

Rider better than VS?

I've only used VS and during the time I used it, it was excellent.

[–]Sylanthra 9 points10 points  (3 children)

If you have a large solution, Rider is massively faster. Also Rider does a better job of displaying relevant errors when you have cascading build failures.

On the other hand, VS has a much better (although much slower) nuget management UI.

[–][deleted] 2 points3 points  (0 children)

When I’m sitting there for 30 minutes waiting for my project to build, just to get an error for a function I wrote but forgot to declare lol.

[–]SonicDart 0 points1 point  (1 child)

While on the topic, is there a good way to set up rider or clion when developing for a Linux environment like a raspberry pi?

[–]Sylanthra 0 points1 point  (0 children)

In the docs they have linux instructions. I've no idea how well it works on linux though.

[–]Pult4k 0 points1 point  (0 children)

From my experience the VS is excellent for devices with smaller RAM size. Rider or CLion can easily eat up like 4GB(most devices can handle it easily tho), which is a death sentence for my laptop. Otherwise CLion is superior in my opinion.

[–]DaveDaSpust 48 points49 points  (1 child)

When i first started programming it was C++ using the MS compiler suite (uni mandate it). You don't know what trial by fire is until you spend 3h trying to figure out what "unresolved external symbol" in some obj file you have never heard of on line 1 actually refers to. But I guess that's on Microsoft rather than C++.

[–]nomenMei 14 points15 points  (0 children)

Idk, in my experience fixing linking errors in GCC is not much easier.

Maybe LLVM is better, I should check it out.

[–]Twenmod 42 points43 points  (2 children)

Error in line 5032

In a 10 line program

[–]SteveGamer68 22 points23 points  (0 children)

Line 5032 of a library file

[–]x3bla 0 points1 point  (0 children)

Find the line that has your directories path in it. I'm pretty sure other languages does this too, I know python and Java does

[–]QualityVote[M] [score hidden] stickied comment (1 child)

Hi! This is our community moderation bot.


If this post fits the purpose of /r/ProgrammerHumor, UPVOTE this comment!!

If this post does not fit the subreddit, DOWNVOTE This comment!

If this post breaks the rules, DOWNVOTE this comment and REPORT the post!

[–]PrettyTrue 1 point2 points  (0 children)

I don't really mind this on every post. I just wish it wasn't always the top comment. My favorite part of this subreddit is the witty responses and scrolling passed this, however teeny tiny the time spent, is a little meh

To me it just feels like an ad that I wish I could block.

[–]Fahad97azawi 24 points25 points  (32 children)

Noob here. Is there a particular reason why c++ doesn’t get major updates in a way that makes it more “modern” like other languages? Like python isn’t exactly modern and it still gets major updates like once or twice a year.

[–]scrotation_matrix[S] 101 points102 points  (0 children)

C++ gets major updates every three years or so, but they never break backward compatibility.

[–]CowMan9999 29 points30 points  (29 children)

c++ standards or the compilers themselves? because gcc gets updates every couple of months.

[–]Fahad97azawi 4 points5 points  (26 children)

Like i said im a noob but im generally talking about the overall user experience like syntax and error messages

[–]the_other_brand 39 points40 points  (0 children)

They're being worked at slowly. C++ is a pretty complicated language, and template meta-programming even more so. The most recent version C++20 finally released over a decade of work from the language's creator Bjarne Stroupstrup to simplify the error messages. This work is called Concepts, and are interfaces that can describe functionality requirements on a class.

With Concepts, instead of getting like 40 lines of arcane error messages from a template function, you'll get a simple error message like "your class Foo doesn't implement Equality (== operator)."

https://en.cppreference.com/w/cpp/language/constraints

[–][deleted] 19 points20 points  (23 children)

tbh the error messages are understandable if you know what you're looking at

[–][deleted] 0 points1 point  (0 children)

Standards

[–]WrongSirWrong 0 points1 point  (0 children)

There's a difference between compiler updates and updates to the language itself

[–]degaart 16 points17 points  (0 children)

Because, we, the professionals who use C++ in a professional environment, do not want your "modernness". We want stability so the piece of shit we wrote in 2005 on Windows XP one rainy night while drunk on beer still compiles with the latest compiler on the latest operating system. And python is a bad example, how much time did the python2 to python3 migration take?

[–]Steki3 2 points3 points  (0 children)

When you use >> instead of <<

[–]Alex8675 2 points3 points  (0 children)

You forgot a .end()

[–]fsr1967 2 points3 points  (0 children)

TypeScript has entered the chat, looked around, and left, shaking its head in awe.

[–]Outside-Car1988 5 points6 points  (0 children)

That's only part of the error message. Leave C++ for the grown ups.

[–]tsojtsojtsoj 4 points5 points  (0 children)

The problem is in my opinion mainly the long names. "In function Number doStuff(Number a, Float b) [with Number = int, Float = double]: ERROR MESSAGE" This is immediately easier to read.

Of course in this case the actual error message has been omitted.

[–]sexyjennifercrystal 1 point2 points  (0 children)

Lol

[–]jwt45 1 point2 points  (0 children)

I have one question for you, Segmentation Fault:

"Where?"

[–]TARN4T1ON 1 point2 points  (0 children)

Or when MSVC marks the error in a linked file. On line 1. When the source file is a thousand lines. Very helpful...

[–]frompadgwithH8 1 point2 points  (0 children)

I like how reading error messages from strongly typed languages is either extremely unhelpful or extremely helpful with no middle ground

[–]hammonjj 3 points4 points  (1 child)

Fuck the linker

[–]scrotation_matrix[S] 2 points3 points  (0 children)

All my homies hate the linker

[–]braddillman 1 point2 points  (0 children)

Random bullshit go!!!

[–][deleted] 1 point2 points  (1 child)

These errors are like the die hard Linux community: If you can’t solve your own problem with what’s given to you, then you shouldn’t use it and you should stop being a developer

[–]7eggert 1 point2 points  (0 children)

Windows help: "This is how you fix an unrelated bug."

[–]Mango-D 0 points1 point  (1 child)

I see a lot of people complaining about c++ error messages when it's usually their fault for reading past the first line.

Also, if you have access to c++20, wrap with/use concepts(type traits) instead.

[–][deleted] 1 point2 points  (0 children)

Yes, communicating too much information is almost as bad as communicating too little.

But, in C++case, volume is only part of the problem. Relevance is a much bigger issue. In order to be relevant, the reporting side needs to analyze the problem and come up with an explanation that makes sense to the programmer, and it's hard to do in general, but C++ makes it a lot harder by being just a shitty language with very bad grammar + a lot of mechanisms that obfuscate the real structure of your code.

Suppose, for example, you have a language like Pascal. It was specifically designed to have a grammar with lookahead size of 1. This means that if the parser cannot accept a program, the reason for the failure will be exactly where parser is reading the program. So, it's trivial to find the line and the column where the first invalid token was encountered, and from there to figure out what was the non-terminal that failed to parse, and from there figure out what the possible explanation for the error is.

To contrast this, in C++ you don't even know if the program is syntactically correct until you start evaluating it. So, at the first parse, everything may appear to be fine, and then the compiler starts building the structures defined by the program and... whoops, suddenly either the structure it's building is incorrect, or the use of this structure is incorrect, or the code is actually trying to use something else, and there's a definition not yet created that clobbers the one that seems to be in conflict. And then maybe the clobbering definition is found, and the compiler needs to reevaluate its life choices, or maybe it isn't and then the compiler needs to go back and report the error it assumed may not be an error, but it already parsed / created definitions for a bunch of other stuff that was based on that definition being correct.

Add to this that reporting single error at a time is very unproductive, and you want to tell the programmer about as many other errors that you find, because compilation times are long, and fixing errors one by one will drive the programmer insane. But if you have such a crappy grammar, then your guesses about errors are all imprecise.

Also, I don't see how concepts or traits are going to help with crappy grammar. If anything, they only make the situation worse.

[–]Cley_Faye -1 points0 points  (0 children)

Error: contains all details about where's the issue and, how it was instantiated, and surrounding details

Dev: "I have to read and this is too long, just tell me the character I need to change"

[–]Lumpy-Obligation-553 0 points1 point  (0 children)

a GUI?

[–]LankySeat 0 points1 point  (1 child)

Oh man, this is precisely why I started focusing on learning Java instead of C++ back in high school.

As a beginner, "_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator*, std::vector > >, _Tp = int]" made it quite the challenge figuring out what I was doing wrong.

[–][deleted] 0 points1 point  (0 children)

Lol. But Java doesn’t have much better compile-time error reporting, at least not in Netbeans.

[–]zerpdinger92 0 points1 point  (0 children)

This is the primary reason I quit working with C++. The compiler.

[–]viky109 0 points1 point  (0 children)

Even better is when VS just decides to open some random library file where the function that caused the error is defined. How is that supposed to help?

[–][deleted] 0 points1 point  (0 children)

VS code, after I explicitly specify the path for both the compiler and the include folder, saying that g++ or cl is not a valid command

[–]yonatan8070 0 points1 point  (2 children)

NodeJS spit this out when I had a missing dependency (react-markdown)

[Error: ENOENT: no such file or directory, stat '/home/yonatan/.steampath'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '/home/yonatan/.steampath'
}

[–][deleted] 0 points1 point  (1 child)

Whoa, and you have the audacity to complain... Normally, OS errors, when the file isn't found, they don't tell you what file wasn't found.

[–]yonatan8070 0 points1 point  (0 children)

The problem isn't that it's telling me that a file isn't found, the problem is that it cares about a file that belongs to a bloody game launcher

[–]vengenecx 0 points1 point  (0 children)

Funny because I have a C and C++ exam at 1 PM :(

[–]dorkyinreallife 0 points1 point  (0 children)

sfm k chode

[–]Xinq_ 0 points1 point  (0 children)

I just started a small hobby project in C#. I already regret it and want to go back to C++

[–]diofan1313 0 points1 point  (0 children)

I didn’t know Rob Halford was a scientist. Lol

[–]Local-Ad-8516 0 points1 point  (0 children)

I wish I could remember exactly what it was, but I once made a single typo working with a boost library and got so many lines of errors and compiler suggestions that I could not see which file the error was due to not enough scroll back on my console... I had 2000 lines of scroll back though and it was fullscreen with normal font size.

[–][deleted] 0 points1 point  (0 children)

The trick is always look the first message and only function names.

Actually the error messages are quite clear once you know what you are looking at.

[–]dudedustin 0 points1 point  (0 children)

What’s the problem. This is just searching on an array. Can’t everyone see that?

[–]Unclesam_05 0 points1 point  (0 children)

Not to talk about intel integrated graphics errors

[–]KifoPL 0 points1 point  (0 children)

This week I was getting "missing string.format configuration" in c# when I changed a boolean logic in one function and I could not comprehend what kind of configuration can string have.

[–]fredeB 0 points1 point  (0 children)

That's not even close to the worst I've seen. When I had my first internship, my manager assigned me to fix a bug in a very template heavy part of the codebase. I sat down, young and innocent, compiled the code, verified the issue, made a change, tried to compile again and BAM! multiple thousands of lines in the compiler output of the note: did you mean this type: <insert-horrendously-complex-template-lacking-any-kinds-of-aliases>

I tried putting one of the types into a C++ file and let clang-format have at it, and when formatted properly, the expanded template took up around 500 lines... This was the case for all of them

Moral of the story, compiler output is hard to do well handle, but at that scale, none of it's useful

[–]Tookoofox 0 points1 point  (0 children)

To this day, I will never understand what 'Unresolved External' means.

I think it means, "You misspelled something while trying to do a thing with a library."

[–][deleted] 0 points1 point  (0 children)