frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

C++ says “We have try at home”

https://devblogs.microsoft.com/oldnewthing/20251222-00/?p=111890
43•ibobev•5h ago

Comments

jasode•2h ago
The submitted title is missing the salient keyword "finally" that motivates the blog post. The actual subtitle Raymond Chen wrote is: "C++ says “We have try…finally at home.”"

It's a snowclone based on the meme, "Mom, can we get <X>? No, we have <X> at home." : https://www.google.com/search?q=%22we+have+x+at+home%22+meme

In other words, Raymond is saying... "We already have Java feature of 'finally' at home in the C++ refrigerator and it's called 'destructor'"

To continue the meme analogy, the kid's idea of <X> doesn't match mom's idea of <X> and disagrees that they're equivalent. E.g. "Mom, can we order pizza? No, we have leftover casserole in the fridge."

So some kids would complain that C++ destructors RAII philosophy require creating a whole "class X{public:~X()}" which is sometimes inconvenient so it doesn't exactly equal "finally".

thombles•1h ago
HN has some heuristics to reduce hyperbole in submissions which occasionally backfire amusingly.
tux3•1h ago
It's rare to see the mangling heuristics improve a title these days. There was a specific type of clickbait title that was overused at the time, so a rule was created. And now that the original problem has passed, we're stuck with it.
mort96•1h ago
Yeah it's a huge mistake IMO. I see it fucking up titles so frequently, and it flies in the face of the "do not editorialise titles" rule:

    [...] please use the original title, unless it is misleading or linkbait; don't editorialize.
It is much worse, I think, to regularly drastically change the meaning of a title automatically until a moderator happens to notice to change it back, than to allow the occasional somewhat exaggerated original post title.

As it stands, the HN title suggests that Raymond thinks the C++ 'try' keyword is a poor imitation of some other language's 'try'. In reality, the post is about a way to mimic Java's 'finally' in C++, which the original title clearly (if humorously) encapsulates. Raymond's words have been misrepresented here for over 4 hours at this point. I do not understand how this is an acceptable trade-off.

vidarh•38m ago
I'm curious about the actual origin now, given that a quick search shows only vague references or claim it is recent, but this meme is present in Eddie Murphys "Raw" from 1987, so it is at least that old.
mojuba•1h ago
I like how Swift solved this: there's a more universal `defer { ... }` block that's executed at the end of a given scope no matter what, and after the `return` statement is evaluated if it's a function scope. As such it has multiple uses, not just for `try ... finally`.
dwattttt•1h ago
I was contemplating what it would look like to provide this with a macro in Rust, and of course someone has already done it. It's syntactic sugar for the destructor/RAII approach.

https://docs.rs/defer-rs/latest/defer_rs/

troglo-byte•27m ago

    #include <iostream>
    #define RemParens_(VA) RemParens__(VA)
    #define RemParens__(VA) RemParens___ VA
    #define RemParens___(...) __VA_ARGS__
    #define DoConcat_(A,B) DoConcat__(A,B)
    #define DoConcat__(A,B) A##B
    #define defer(BODY) struct DoConcat_(Defer,__LINE__) { ~DoConcat_(Defer,__LINE__)() { RemParens_(BODY) } } DoConcat_(_deferrer,__LINE__)

    int main() {
        {
            defer(( std::cout << "Hello World" << std::endl; ));
            std::cout << "This goes first" << std::endl;
        }
    }
_nalply•15m ago
Your code has a bug! Why doesn't this work?

    defer(( some_code )); defer(( more_code ));
    </s>
rezonant•13m ago
Why would that be preferable to just using an RAII style scope_exit with a lambda
tryfinally•1h ago
I always wonder whether C++ syntax ever becomes readable when you sink more time into it, and if so - how much brain rewiring we would observe on a functional MRI.
sigmoid10•1h ago
It does... until you switch employers. Or sometimes even just read a coworker's code. Or even your own older code. Actually no, I don't think anyone achieved full readability enlightenment. People like me just hallucinated it after doing the same things for too long.
usrnm•59m ago
And yet, somehow Lisp continues to be everyone's sweetheart, even though creating literal new DSLs for every project is one of the features of the language.
vkazanov•12m ago
Lisp doesnt have much syntax to speak of. All of the DSLs use the same basic structure and are easy to read.

Cpp has A LOT A of syntax: init rules, consts, references, move, copy, templates, special cases, etc. It also includes most of C, which is small but has so many basic language design mistakes that "C puzzles" is a book.

Yoric•41m ago
Sadly, that is exactly my experience.
m-schuetz•1h ago
"using namespace std;" goes a long way to make C++ more readable and I don't really care about the potential issues. But yeah, due to a lack of a nice module system, this will quickly cause problems with headers that unload everything into the global namespace, like the windows API.

I wish we had something like Javascript's "import {vector, string, unordered_map} from std;". One separate using statement per item is a bit cumbersome.

delta_p_delta_x•14m ago
Standard library modules: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p24...

I have thoroughly forgotten which header std::ranges::iota comes from. I don't care either.

deliciousturkey•32m ago
In my opinion, C++ syntax is pretty readable. Of course there are codebases that are difficult to read (heavily abstracted, templated codebases especially), but it's not really that different compared to most other languages. But this exists in most languages, even C can be as bad with use of macros.

By far the worst in this aspect has been Scala, where every codebase seems to use a completely different dialect of the language, completely different constructs etc. There seems to have very little agreement on how the language should be used. Much, much less than C++.

winternewt•7m ago
Destructors are vastly superior to the finally keyword because they only require us to remember a single time to release resources (in the destructor) as opposed to every finally clause. For example, a file always closes itself when it goes out of scope instead of having to be explicitly closed by the person who opened the file. Syntax is also less cluttered with less indentation, especially when multiple objects are created that require nested try... finally blocks. Not to mention how branching and conditional initialization complicates things. You can often pair up constructors with destructors in the code so that it becomes very obvious when resource acquisition and release do not match up.

Calendar

https://neatnik.net/calendar/?year=2026
467•twapi•7h ago•69 comments

Growing up in “404 Not Found”: China's nuclear city in the Gobi Desert

https://substack.com/inbox/post/182743659
85•Vincent_Yan404•5h ago•22 comments

Replacing JavaScript with Just HTML

https://www.htmhell.dev/adventcalendar/2025/27/
424•soheilpro•11h ago•144 comments

How we lost communication to entertainment

https://ploum.net/2025-12-15-communication-entertainment.html
463•8organicbits•15h ago•227 comments

C++ says “We have try at home”

https://devblogs.microsoft.com/oldnewthing/20251222-00/?p=111890
43•ibobev•5h ago•19 comments

Fathers’ choices may be packaged and passed down in sperm RNA

https://www.quantamagazine.org/how-dads-fitness-may-be-packaged-and-passed-down-in-sperm-rna-2025...
212•vismit2000•10h ago•120 comments

Floor796

https://floor796.com/
759•krtkush•22h ago•96 comments

Hacking a Java Minecraft server with memory overflows [video]

https://www.youtube.com/watch?v=Zy6Ci-K-0K8
28•jblazevic•3d ago•1 comments

The Origins of APL (1974) [video]

https://www.youtube.com/watch?v=8kUQWuK1L4w
28•ofalkaed•6d ago•3 comments

Rex is a safe kernel extension framework that allows Rust in the place of eBPF

https://github.com/rex-rs/rex
66•zdw•5d ago•41 comments

I stayed in a $40 capsule hotel (London)

https://www.cnbc.com/2025/12/20/zedwell-capsule-hotel-i-stayed-in-a-40-dollar-capsule-hotel-in-lo...
9•fcpguru•5d ago•1 comments

Gpg.fail

https://gpg.fail
367•todsacerdoti•19h ago•201 comments

Dialtone – AOL 3.0 Server

https://dialtone.live/
54•rickcarlino•8h ago•24 comments

Functional programming and reliability: ADTs, safety, critical infrastructure

https://blog.rastrian.dev/post/why-reliability-demands-functional-programming-adts-safety-and-cri...
93•rastrian•12h ago•82 comments

Rainbow Six Siege hacked as players get billions of credits and random bans

https://www.shanethegamer.com/esports-news/rainbow-six-siege-hacked-global-server-outage/
201•erhuve•16h ago•62 comments

Project Vend: Phase Two

https://www.anthropic.com/research/project-vend-2
137•kubami•5d ago•41 comments

Text rendering hates you (2019)

https://faultlore.com/blah/text-hates-you/
145•andsoitis•6d ago•56 comments

Immer – A library of persistent and immutable data structures written in C++

https://github.com/arximboldi/immer
89•smartmic•6d ago•10 comments

An experiment in separating identity, memory, and tools

https://RCRDBL.com
6•promptfluid•1d ago•2 comments

Windows 2 for the Apricot PC/Xi

https://www.ninakalinina.com/notes/win2apri/
129•todsacerdoti•17h ago•30 comments

Liberating Bluetooth on the ESP32

https://exquisite.tube/w/mEzF442Q4hUXnhQ8HmfZuq
68•todsacerdoti•13h ago•11 comments

Show HN: Ez FFmpeg – Video editing in plain English

http://npmjs.com/package/ezff
370•josharsh•1d ago•183 comments

Plugins case study: mdBook preprocessors

https://eli.thegreenplace.net/2025/plugins-case-study-mdbook-preprocessors/
8•ingve•6d ago•2 comments

Nvidia's $20B antitrust loophole

https://ossa-ma.github.io/blog/groq
465•ossa-ma•18h ago•143 comments

Say No to Palantir in the NHS

https://notopalantir.goodlawproject.org/email-to-target/stop-palantir-in-the-nhs/
348•_____k•14h ago•104 comments

The Dangers of SSL Certificates

https://surfingcomplexity.blog/2025/12/27/the-dangers-of-ssl-certificates/
58•azhenley•13h ago•74 comments

OrangePi 6 Plus Review

https://boilingsteam.com/orange-pi-6-plus-review/
172•ekianjo•23h ago•150 comments

Ask HN: Resources to get better at outbound sales?

202•sieep•6d ago•57 comments

Public Domain Day 2026

https://web.law.duke.edu/cspd/publicdomainday/2026/
46•rolph•13h ago•2 comments

Janet Jackson had the power to crash laptop computers (2022)

https://devblogs.microsoft.com/oldnewthing/20220816-00/?p=106994
283•montalbano•18h ago•107 comments