frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Map: Operator[] Should Be Nodiscard

https://quuxplusone.github.io/blog/2025/12/18/nodiscard-operator-bracket/
39•jandeboevrie•4d ago

Comments

reactordev•2h ago
My pet peeve with c++ is exactly this. Either it’s not wise to call release, or it is (under circumstances) and yet the developer has no idea whether their scenario applies (tip: it doesn’t, 90% of the time).

The stdlib is so bloated with these “Looks good, but wait” logic bombs.

I wish someone would just draw a line in the sand and say “No, from here on out, this is how this works and there are no other scenarios in which there needs a work around”. This is why other systems languages are taking off (besides the expressiveness or memory safety bandwagon) is because there are clear instructions in the docs on what this does with examples of how to use it properly.

Most c++ codebases I’ve seen the last 10 years are decent (a few are superb) and I get that there’s old code out there but at what point do we let old dogs die?

GuB-42•37m ago
C++ has always been a "kitchen sink" language, it is used in many different ways and drawing any line may alienate an entire industry.

> This is why other systems languages are taking off

Great! It is not a competition. If you think that Rust is a better choice, use Rust, don't make C++ into Rust. Or maybe try Carbon, it looks like it is the language you want. But if you have some old dogs you want to keep alive, then use C++, that's what it is for.

reactordev•26m ago
I get it, I do. There’s a lot of old code out there. My point wasn’t that old dogs are bad. My point was about changing how we care for them.

If you have old code that you want to compile, use -c98 or whatever to peg it to that. Leave the rest of us alone to introduce more modern ways of things. I’d even be happy to see removal of things.

pjmlp•30m ago
> This is why other systems languages are taking off

For the time being that are still being written with C++ infrastructure though.

It would be great if those wannabe C++ replacements were fully bootstraped.

reactordev•17m ago
Go compiles go, not sure what you mean by wannabe c++.

There’s a frontend to gcc for go and working on rust. Is it the use of gcc you dislike? You’re going to have to explain some more.

We’re stuck on ASM/ELF. We’re stuck on C of some kind. Maybe in the future LLMs can help us write low-level / high expressiveness code but until we get rid of 1970s “personal computer” decisions in silicon, we’re stuck with it.

SJC_Hacker•17m ago
> t would be great if those wannabe C++ replacements were fully bootstraped

This would require (re)writing the OS in the replacement language

Also need assembler to be taken seriously, which Rust can’t do last I checked

fn-mote•2h ago
Title could be “ugly C++ idioms prevent map::operator[] from being [[nodiscard]]”.

Many of the uses are in Google’s codebase.

Overall very technical- interesting if you are a library writer or maybe if you care about long term improvements in your C++’legacy codebase.

rwmj•2h ago
https://en.cppreference.com/w/cpp/language/attributes/nodisc... .. in case anyone else was wondering. It seems to mean the compiler should warn if you ignore the result except by an explicit cast to void.
larusso•1h ago
Thanks. I was wondering what this means practically. So they rolled this back because Google who compile with warnings as errors can’t fix these lines? Must be great to be Google and on all these boards. I on the other hand have to deal constantly with breaking changes left and right because someone decided, among them Google (16KB page tables anyone), that going forward stuff works differently.
junon•1h ago
For the Rust inclined, [[nodiscard]] is #[must_use], if you were confused.

Anyway, this article illustrates a great reason why C++ is a beautiful mess. You can do almost anything with it, and that comes at a cost. It's the polar opposite ethos of "there should be one clear way to do something" and this sort of thing reminds me why I have replaced all of my systems language needs with Rust at this point, despite having a very long love/hate relationship with both C and C++.

Totally agree it should be marked as nodiscard, and the reasoning for not doing so is a good example of why other languages are taking over.

bayesnet•53m ago
It’s also worth noting that in rust you don’t need to be as worried about marking a function #[must_use] if there is a valid reason some of the time to discard the value. One can just assign like so `let _ = must_use_fn()` which discards the value and silences the warning. I think this makes the intent more clear than casting to void as TFA discusses.
on_the_train•43m ago
There is in c++, too (std::ignore). Not sure why the author decided to go with the ancient void cast
the_mitsuhiko•45m ago
Interestingly Index::index is also usually not marked as `#[must_use]` in Rust either.
junon•22m ago
I don't believe you can mark trait methods with #[must_use] - it has to be on the implementation. Not near a compiler to check at the moment.

In the case of e.g. Vec, it returns a reference, which by itself is side-effect free, so the compiler will always optimize it. I do agree that it should still be marked as such though. I'd be curious the reasons why it's not.

pjmlp•34m ago
I disagree with the conclusion, other languages are taking over because they have the advantage of not having 40 years of production code history, and those adopting them don't care about existing code.

You will find similar examples in Python, Java, C#,... and why not everyone is so keen into jumping new language versions.

dooglius•1h ago
`try_emplace` is not a huge improvement since it overloads the existing keyword "try" to mean something pretty different. Should be `emplace_if_absent`/`insert_if_absent` but changing the API of stdlib would require going through a huge formal process
themafia•1h ago
Ah, and because this is C++, the standard map having typed template parameters, which could be a non pointer, they're forced to make operator[] have this semantic:

Returns a reference to the value that is mapped to a key equivalent to key or x respectively, performing an insertion if such key does not already exist.

Which is a bit of a surprise coming from mostly C and Go.

j1elo•1h ago
C++ could try to approach the "stability without stagnation" model.

Add an opt-in compiler flag --edition='26' which, when used, applies the breaking changes defined for C++26. Then users like Google or others who have been (ab)using some features for their side effects can decide to stay on the older versions.

pjmlp•29m ago
It already exists, --std=c++26.
ivanjermakov•29m ago
Another default that Zig got right: every non-void result must be handled.

https://github.com/ziglang/zig/issues/219

When Compilers Surprise You

https://xania.org/202512/24-cunning-clang
23•brewmarche•1h ago•5 comments

The Port I couldn't Ship

https://ammil.industries/the-port-i-couldnt-ship/
35•cjlm•5d ago•6 comments

Fabrice Bellard Releases MicroQuickJS

https://github.com/bellard/mquickjs/blob/main/README.md
1228•Aissen•21h ago•446 comments

Some Epstein file redactions are being undone with hacks

https://www.theguardian.com/us-news/2025/dec/23/epstein-unredacted-files-social-media
692•vinni2•18h ago•523 comments

Your Inbox Is a Bandit

https://parentheticallyspeaking.org/articles/bandit-inbox/
17•zdw•2d ago•6 comments

X-ray: a Python library for finding bad redactions in PDF documents

https://github.com/freelawproject/x-ray
537•rendx•17h ago•94 comments

Unifi Travel Router

https://blog.ui.com/article/travel-in-style-unifi-style-unifi-travel-router
348•flurdy•14h ago•288 comments

The e-scooter isn't new – London was zooming around on Autopeds a century ago

https://www.ianvisits.co.uk/articles/the-e-scooter-isnt-new-london-was-zooming-around-on-autopeds...
38•zeristor•6h ago•17 comments

Google 2025 recap: Research breakthroughs of the year

https://blog.google/technology/ai/2025-research-breakthroughs/
114•Anon84•5h ago•75 comments

Super Mario Bros. and Yoshi Games (Yields) Reduced Burnout Risk

https://games.jmir.org/2025/1/e84219/
5•azalemeth•1h ago•0 comments

Scaling Go Testing with Contract and Scenario Mocks

https://funnelstory.ai/blog/engineering/scaling-go-testing-with-contract-and-scenario-mocks
19•preetamjinka•5d ago•4 comments

Nabokov's guide to foreigners learning Russian

https://twitter.com/haravayin_hogh/status/2003299405907247502
150•flaxxen•13h ago•259 comments

Permission Systems for Enterprise That Scale

https://eliocapella.com/blog/permission-systems-for-enterprise/
31•eliocs•5h ago•13 comments

Show HN: Tonbo – an embedded database for serverless and edge runtimes

https://github.com/tonbo-io/tonbo
39•ethegwo•6d ago•11 comments

Map: Operator[] Should Be Nodiscard

https://quuxplusone.github.io/blog/2025/12/18/nodiscard-operator-bracket/
39•jandeboevrie•4d ago•20 comments

Lua 5.5

https://lua.org/versions.html#5.5
346•km•2d ago•111 comments

Show HN: Turn raw HTML into production-ready images for free

https://html2png.dev
111•alvinunreal•12h ago•52 comments

I rebuilt FlashAttention in Triton to understand the performance archaeology

https://aminediro.com/posts/flash_attn/
58•amindiro•3d ago•6 comments

Texas app store age verification law blocked by federal judge

https://www.macrumors.com/2025/12/23/texas-app-store-law-blocked/
256•danso•17h ago•184 comments

Don't Become the Machine

https://armeet.bearblog.dev/becoming-the-machine/
143•armeet•11h ago•77 comments

AMD entered the CPU market with reverse-engineered Intel 8080 clone 50 years ago

https://www.tomshardware.com/pc-components/cpus/amd-first-entered-the-cpu-market-with-reverse-eng...
4•ksec•38m ago•1 comments

Perfect Software – Software for an Audience of One

https://outofdesk.netlify.app/blog/perfect-software
168•ggauravr•4d ago•67 comments

Proving Bounds for the Randomized MaxCut Approximation Algorithm in Lean4

https://abhamra.com/blog/randomized-maxcut/
45•todsacerdoti•4d ago•1 comments

Open source USB to GPIB converter (for Test and Measurement instruments)

https://github.com/xyphro/UsbGpib
56•v15w•13h ago•25 comments

Avoid Mini-Frameworks

https://laike9m.com/blog/avoid-mini-frameworks,171/
55•laike9m•3h ago•52 comments

Autonomously navigating the real world: lessons from the PG&E outage

https://waymo.com/blog/2025/12/autonomously-navigating-the-real-world
113•scoofy•12h ago•86 comments

Donald E. Knuth and Peter van Emde Boas on priority deques (1977) [pdf]

https://staff.fnwi.uva.nl/p.vanemdeboas/knuthnote.pdf
50•vismit2000•12h ago•2 comments

HTTP Caching, a Refresher

https://danburzo.ro/http-caching-refresher/
134•danburzo•19h ago•20 comments

Fifty problems with standard web APIs in 2025

https://zerotrickpony.com/articles/browser-bugs/
157•dhruv3006•6d ago•66 comments

New reactor produces clean energy and carbon nanotubes from natural gas

https://phys.org/news/2025-12-reactor-energy-carbon-nanotubes-natural.html
5•westurner•28m ago•4 comments