C++ says “We have try... finally at home”
HN title mangling and meme confusion
- The original blog title referenced the meme “we have X at home” and specifically “try…finally”; the HN-submitted title dropped “finally,” changing the meaning.
- Commenters argue this misrepresents the post (sounds like a criticism of
try, not a discussion offinally-like behavior) and violates HN’s “don’t editorialize titles” norm. - Some defend HN’s automatic de-clickbaiting as mostly effective; others call it a persistent “bug” that often distorts titles and depends too much on users emailing mods.
- There is debate over whether using memes in technical titles is wise, since non‑cultural insiders may miss the joke entirely.
Destructors, RAII, and “finally”
- One camp: C++ destructors and RAII are strictly superior to
finallyfor resource management: you write cleanup logic once in the destructor, not in everyfinallyblock, and nested try/finally indentation disappears. - Opposing view:
finallyand destructors solve different problems—destructors encode ownership;finallyis function/scope‑level cleanup for arbitrary actions, including things you can’t or shouldn’t model as an object. - Critics of “just write a class” say it’s overkill for a one‑line cleanup; defenders respond that serious resources should already be wrapped in RAII types, and ad‑hoc scope guards or library helpers cover the rest.
Defer, context managers, and other languages
- Swift and Go’s
deferare praised as more general “run at scope exit” constructs that don’t add nesting and place setup and teardown near each other in the code. - Others prefer Python‑style context managers / C#
using/ Java try‑with‑resources, arguing they make ownership explicit, at the cost of extra syntax and indentation. - There’s discussion of macro‑ and library‑based scope guards in C++ and Rust that approximate
defer.
Exceptions, destructors, and finally footguns
- Several comments focus on error semantics: many languages let exceptions from
finallyoverride the original, which is considered a design mistake that hides the root cause. - C++’s rule that an uncaught exception thrown during stack unwinding terminates the program is criticized as harsh; others say it’s necessary and that destructors “shouldn’t throw” in practice.
- Java‑style
finallyis shown to allow pathologically confusing control flow (e.g., returning fromfinallyand discarding a thrown error).