7 ms·
Retiring a favourite C++ joke
- justincredible 4y ago[dead]
- hinkley 4y agoWe are all getting old. College age kids aren't old enough to remember when that show was on the air.
- deleted 4y ago[deleted]
- hummus_bae 4y agoI am also 29 and I'm old enough to remember Dawson's Creek, but I don't watch a lot of TV so I've never seen it.
- kordite 4y agoIf you find yourself with the time, and the inclination, give Arrested Development a go. I thought it was fantastic. I think there is a reason that it always sat a little under the radar. You have to actively watch it. It's not suited to being on in the background.
- kordite 4y agoYes, and I fear that I have not seen or understood a lot of the cultural references/jokes that they would understand.
- pcthrowaway 4y agoIt's one joke Martin. What could it cost, ten dollars?
- kordite 4y agoAhhh, man. I wish I had thought of that to include in blog text.
- favorited 4y agoThere's dozens of people who would get it... DOZENS!
- cozzyd 4y agoyes, I would have thought the "better" version would be int tobias[24]; delete tobias;
- kordite 4y agoI'll be honest, I didn't get it at first. I thought initially that it was too complex for the teaching example. And then it clicked. You're rather smart aren't you! I guess 24, or 36, or 48 would have worked!
- cozzyd 4y agoYeah, I was thinking the number of never-nudes in the world might closer to 2 dozen than 3 or 4 dozen, but I don't really know!
- kjellsbells 4y agoUses C++. Shortly after: I've made a huge mistake.
- favorited 4y agoTobias: You know, Lindsay, as a developer, I have advised... a number of people to explore "modern C++," where everything is RAII, and you never have to write `new` or `delete`. Lindsay: Well, did it work for those people? Tobias: No, it never does. I mean, these people somehow delude themselves into thinking it might, but... but it might work for us.
- zamnos 4y agoAccording to the TIOBE index, C++ is the fourth most popular programming language, and has been around for over 35 years, so easily a couple thousand people. The question is how many of them are on HN (probably dozens).
- globalreset 4y agoI've read it "Rewriting ..." . You guess in what exactly.
- kordite 4y agoMy guess is rust.
- jasoneckert 4y agoIt's an OK C++ joke, but not great. I could certainly give the author a few pointers...
- lisper 4y agoAnd I could add a couple of references.
- zamnos 4y agoI can only use them after they're free.
- kwertyoowiyop 4y agoNarrator: They weren’t actually free.
- jaimehrubiks 4y agoLet's make sure, I'll make a callok?
- nullnotzero 4y agoAnd if that doesn’t work, we can send a malloc?
- deleted 4y ago[deleted]
- gmiller123456 4y agoHow many people read that in Morgan Freeman's voice?
- Panini_Jones 4y agoArrested Development had a narrator: Ron Howard.
- bitwize 4y agoIt's recommended to use virtual destructors for objects that live on the heap. Say you have a base class pointer to an object of a derived class; with nonvirtual destructors the base class determines the destructor that is called, whereas with virtual destructors it's the derived class that chooses the form of the destructor.
- geenew 4y agoMaybe he can mock try next?
- geenew 4y agoBetter phrasing (and good advice!): Don't mock try all the time
- mwcremer 4y agoMy favorite C++ joke is: Have you heard about the new object-oriented version of COBOL? It’s called “ADD 1 TO COBOL”
- saurik 4y agoThat's more like ++C. You need "ADD 1 TO COBOL RETURNING COBOL"... which elicits another C++ joke: that it would have been nice to get to use the better version, but someone used the wrong operator, so what we have is certainly complicated but probably just more of the same.
- eru 4y agoThe ++ is probably overloaded, and actually formats your hard disk, instead of incrementing a number. (Just like >> is overloaded to do IO, instead of shifting bits.)
- smcameron 4y agoMy favorite, best told while among C programmers involuntarily debugging some gnarly C++ is, "Man, I swear, the dude that invented C++ doesn't know the difference between increment and excrement."
- dllthomas 4y agoC++ makes C bigger, returning the same value.
- u801e 4y agoEven the compilers are in on some jokes: $ gcc -xc - <<<"int main(int argc, char **argv) { long long long a; return 0; }" <stdin>: In function ‘main’: <stdin>:1:45: error: ‘long long long’ is too long for GCC
- nvader 4y agoI've watching you!
- klodolph 4y agoThe old MPW compiler had some gems: https://www.cs.cmu.edu/~jasonh/personal/humor/compile.html https://www.cs.cmu.edu/~jasonh/personal/humor/compile.html > This label is the target of a goto from outside of the block containing this label AND this block has an automatic variable with an initializer AND your window wasn't wide enough to read this whole error message
- ddulaney 4y agoOn template expansion failures, I'd love a modern GCC reporting "your window wasn't tall enough to read this whole error message"
- dvh 4y agoI made this compiler joke and received whoping 930 upvotes for it: https://i.redd.it/dp6ixt4ri1hz.png https://i.redd.it/dp6ixt4ri1hz.png
- 4y ago
- photochemsyn 4y agoDo modern cars even allow you to step on the accelerator and the brake at the same time?
- Mawr 4y agoWhy wouldn't they? The brake simply overrides the accelerator.
- cardinalfang 4y agoSportier drivers may wish to brake and accelerate simultaneously (rev matching, weight transfer tricks). Normal cars just cut fuel when braking to avoid two-foot drivers burning their brakes.
- FpUser 4y agoThe other use is for mere mortals to simulate differential lock when it is not there. I've used it couple of times.
- HnUser12 4y agoI guess you technically can’t in an EV with regenerative braking. (But maybe they do have an actual brake pedal?)
- mgsouth 4y agoNon-EV driver here; glad I did a search making the "obvious" reply. Surprisingly, "one pedal driving mode" is a thing. Its described as opt-in with a switch or setting, so I guess there's still a brake pedal. Which means some QA techs must have test plans with "switch off, step on brake pedal" and "switch on, step on brake pedal." Or maybe "switch on, step on brake pedal" is undefined behavior and the compiler can optimize it out.
- cperciva 4y agoMy Kona Electric has brake and accelerator pedals. IIRC if you press both at the same time, the accelerator pedal is ignored.
- omoikane 4y agoMy favorite C++ joke is this limerick that has been in the standard for a while: When writing a specialization, be careful about its location; or to make it compile will be such a trial as to kindle its self-immolation. https://eel.is/c++draft/temp.expl.spec#8 https://eel.is/c++draft/temp.expl.spec#8
- planede 4y agoAn other one from the standard: void trex(volatile short left_arm, volatile short right_arm); // deprecated https://eel.is/c++draft/depr.volatile.type#example-3 https://eel.is/c++draft/depr.volatile.type#example-3
- tialaramex 4y agoThis is one of the surviving improvements from JF Bastien's P1152 which was initially successful in deprecating most of the spurious use of volatile from C++ with a view to some day getting in there and actually doing MMIO properly. Unfortunately too much of this will be unwound in C++ 23 because WG21 voted to un-deprecate all the volatile compound operators despite knowing nobody could even offer a rationale for why or how most of them would ever be correctly used.
- tempodox 4y agoI think [1] explains well why this will be un-deprecated. [1]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2327r1.pdf https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p23...
- tialaramex 4y agoNote that P2327 is not what was actually done. P2327 would be in my "not angry just disappointed" category. Of course WG21 think rotten archaic C code should be valid C++ 23 and the belief from embedded devs who write this stuff that it's probably all fine despite no evidence whatsoever should be enough to sail through committee. WG21 voted to amend the draft to un-deprecate all of the volatile compound assignments instead, at Kona IIRC.
- sacnoradhq 4y ago#include <iostream> using namespace std; class BadProgrammer { public: void yep() { delete this; } }; int main() { auto x = BadProgrammer{}; x.yep(); cout << "You are a terrible engineer and should feel bad, but don't worry because this will never print." << endl; return 0; } g++ -Wall -Wextra -Wpedantic main.cc # compiles just fine clang++ -Wall -Wextra -Wpedantic main.cc # also compiles just fine
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- akhosravian 4y agoFWIW the behavior of delete on a pointer that isn’t either null or returned from new is undefined. So a conforming C++ compiler doesn’t have to diagnose this mistake, and similarly the compiled program doesn’t have to do anything meaningful either. For example, just ignoring the delete and printing the message is as valid a result as the more useful crash at the site of the bad operation.
- AnIdiotOnTheNet 4y agoThat this situation is "working as intended" and there are programmers who do not see a problem with that is... well it makes me despair.
- PaulDavisThe1st 4y agoWhat's your proposed alternative? What does the alternative cost? If non-zero, what mechanism would you use to disable it?
- nneonneo 4y agoHey, it actually works! int main() { int tobias[24] = {0,0,33}; delete(tobias+4); } Compile and run on Ubuntu 20.04 (may work on other Linuxes), no errors, no warnings, runs perfectly fine. Bonus fun: try printing out the address of `tobias` and `new int[6]` afterwards :)
- planede 4y agoI assume you have it on x86_64. I'm trying to make sense of that according to glibc implementation details[1] and Sys V/Itanium ABI. Default new and delete just use malloc/free. First 4 ints are interpreted as prev_size and size. prev_size is 0. 33 is 0b10001, size is 32 (bytes, so 8 ints), AMP is 0b001, so not in arena (default sbrk heap, I assume), not mmap'd, prev is used. I didn't follow how the internal bookkeeping will be updated, but I assume 8 size chunk will be immediately reused on a following `new int[6]`. Obviously don't write code like this. [1] https://sourceware.org/glibc/wiki/MallocInternals https://sourceware.org/glibc/wiki/MallocInternals
- nneonneo 4y agoEssentially correct. 33 sets up the pointer to appear to glibc as if it were a small, “normal” 32-byte allocation. The default behavior for glibc free() with a small allocation size will be to put it into the thread cache (tcache), which makes it immediately available to be reused by the same thread. Although you should obviously never write code like this by yourself, understanding weird details like this is very helpful when exploiting memory error bugs in software, as it lets you understand how precisely to subvert the memory allocator to give you access to desired parts of memory.
- bregma 4y agoWeird that undefined behaviour is undefined. Undefined behaviour is no joke.
- jb1991 4y agoI was surprised to see it not mentioned in the post -- the most obvious reason this joke should be retired is not the reference to a television show but rather the modern practice of never using new or delete at all in C++ code. Modern C++ avoids these pitfalls and I think it's been 10 years since I've written the words the new or delete.
- pjmlp 4y agoThat modern pratice is more theory than practice, even on sample code from ISO C++ members.
- jb1991 4y agoNo, it’s not just theory. Like anything in C++, codebases and their styles widely vary. But my comment holds true for the vast majority of developers I have worked with over the last decade. With the exception of the special “placement new“ operator, it is nearly obsolete to use new and delete.
- pjmlp 4y agoI suggest browsing around code from Microsoft, Google, Apple,... Plus there are those tons of enteprise code, hardly the "vast majority". The only place I see modern C++ as advocated, it at C++ conference talks, and my own hobby coding.
- xiaodai 4y ago[flagged]
- al_be_back 4y ago> void fn() { int tobias; delete &tobias; } <malloc>: ** error pointer being freed was not allocated i wouldn't say that's an illegal op per se, if anything it's a pretty safe op! tobias only ever existed in thought, not in body :( :( maybe a compiler WARN or IGNORED_OP
- ltr_ 4y agofor this kind of errors is why you always leave a comment on your code
- kordite 4y agoThis was another one I didn't get straight away, shame on me! Of course, it helps to remember this: https://www.youtube.com/watch?v=BYTNMCWrxEg https://www.youtube.com/watch?v=BYTNMCWrxEg.
- pklausler 4y agoIf you make a friend only because you want to expose your private member to them, you may be a C++ programmer.
- Am4TIfIsER0ppos 4y agoThe biggest c++ joke must be: cout << this << is << what << they << really << think;
- lr1970 4y agoMy favorite C++ joke -- "Your friends can see your private parts".
- hulitu 3y ago"C++ is to C what lung cancer is to lung". UNIX haters handboook.