frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

C++ move semantics from scratch (2022)

https://cbarrete.com/move-from-scratch.html
36•todsacerdoti•5d ago

Comments

revivalizer•1h ago
This is a really well written article that explains the concepts straightforwardly. I had never bothered to understand this before.

... because I gave up on C++ in 2011, after reading Scott Meyers excellent Effective C++. It made me realize I had no desire to use a language that made it so difficult to use it correctly.

chuckadams•1h ago
I had exactly the same reaction to Effective C++, and I'd learned it back in the 90's (my first compiler didn't even support templates!). It's a wonderful book for sure, but it's a wonderfully detailed map to a minefield. The existence of guidelines like the "Rule of 7" should be raising questions as to why such a rule needs to exist in the first place.

As for this article, it really did de-mystify those strange foo&& things for me. I had no idea that they're functionally identical to references and that what C++ does with them is left up to convention. But I still felt like I had to fight against sanity loss from a horrid realization.

scotty79•29m ago
I don't get what's bad about rule 7. And I haven't really programmed in C++ for a decade. When you are calling derived object through a base class pointer you have a choice if you want to call the function of the base class or the function of the derived class. If you don't make it virtual it's called by pointer type, if you do, it's called by pointee type. Same goes for the destructors with only difference being that in case of virtual destructor the deatructor of a base class will be called automatically after the destructor of the derived class. So basically if you want to override methods or the destructor make your functions virtual, including the destructor.

Does it lead to problems? Surely. Should all metods be virtual by default? Probably. Should there be some keyword that indicates in derived class that a method intentionally shadows a non virtual method from the base class? Yes.

It's not a great human oriented design but it's consistent.

chuckadams•22m ago
Apologies, I was referring to a "Rule of 7", but I more or less hallucinated it, since I'd heard the old "rule of 3" then "rule of 5" had been revised again, and thought they were maybe going with prime numbers?

https://en.cppreference.com/w/cpp/language/rule_of_three.htm...

The confusion kind of speaks for itself. The language is a construction set where the primary building block is razor blades.

ckcheng•1h ago
I retired from wanting to write C++ when Scott Meyers retired from writing more Effective Modern C++.
TimorousBestie•1h ago
The article is a really good exposition of move semantics, but unfortunately many modern C++ features benefit from the pedagogical technique of “imagine this feature didn’t exist, this is why someone would want to develop it.”

I say unfortunately because this doesn’t scale. A junior programmer doesn’t have the time to process 30 years of C++’s historical development.

Mathematics (which has a much longer history and the same pedagogical problem) gets around this by consolidating foundations (Bourbaki-style enriched set theory -> category theory -> homotopy type theory, perhaps?) and by compartmentalization (a commutative algebraist usually doesn’t care about PDEs and vice versa).

I don’t see C++ taking either route, realistically.

cyanmagenta•26m ago
If we want to make the math analogy, C++ seems more like the language of math (basic algebra, the notion of proofs, etc.) that everyone uses, and the compartmentalization comes when you start to apply it to specific fields (number theory, etc.). That same concept exists in the C++ community: the people who care about stuff like asynchronous networking libraries aren’t usually the people who care about SIMD math libraries, and vice versa.

I also wonder if most junior C++ programmers can shortcut a bit by just using common patterns. Articles like these I’ve always thought were geared more toward experienced programmers who are intellectually curious about the inner workings of the language.

einpoklum•3m ago
> I don’t see C++ taking either route, realistically.

But it has been taking the "compartmentalization" route: Once a new, nicer/safer/terser idiom to express something in code emerges, people being taught the language are directed to use that, without looking into the "compartment". Some of this compartmentalization is in the language itself, some in the standard library, and some is more in the 'wild' and programming customs.

It's true, though, that if you want to write your own library, flexibly enough for public use - or otherwise cater to whatever any other programmer might throw at you - you do have to dive in rather deep into the arcane specifics.

pesfandiar•2m ago
Mathematics doesn't need to remain backward compatible.
criemen•45m ago
Would it be fair to say that things are so complicated (compared to all other programming languages I've used in my professional life), because C++ pre-move semantics defaulted to deep copy semantics? It seems to be set apart in that choice from many other languages.
htfy96•39m ago
Correct. As someone who maintain a 16-year-old C++ code base with new features added every day, The status quo is the best incremental improvement over deep copy semantics.

There are better choices if everything is built from scratch, but changing wheels from a running car isn't easy.

einpoklum•10m ago
Sorry to be the nitpicker here, but - the best incremental improvement would probably have seen move-destruction instead of just moves, which keep the source object alive and force the allowance for a valid 'empty' or 'dummy' state.

See also:

* https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n13... move designs

* https://www.foonathan.net/2017/09/destructive-move/

kccqzy•15m ago
Deep copy is pedagogically and semantically the right choice for any mutable containers. You either make containers immutable or copies deep. Otherwise it's just an invitation for subtle bugs.
criemen•11m ago
I'm not sure about that - every time I copy an object I have to think through what happens, no matter the default semantics. C++ makes the deep copy case easier than other programming languages without top-level built-in support.
mlmonkey•39m ago
Whenever I'm dealing with C++, I get tripped by the most basic of things: like for example, why use "&&" for what appears to be a pointer to a pointer? And if this indeed the case, why is int&& x compatible with int& y ?? Make up your mind: is it a pointer to a pointer, or a pointer to an int?!?

I have steadfastly avoided dealing with C++ for almost 30 years, and I am grateful that I did not have to. It seems like such a messy language with overloaded operators and symbols ( don't even get me started on Lambdas!)

wocram•32m ago
&& is not a pointer to a pointer, it's a temporary value. There is a huge amount of cognitive overhead in normal cpp usage because over time we have found that many of the default behaviors are wrong.
TinkersW•30m ago
If you had read like even the basic part of that article you would know that && is not a pointer to a pointer.

Anyway C++ isn't as complicated as people say, most of the so called complexity exists for a reason, so if you understand the reasoning it tends to make logical sense.

You can also mostly just stick to the core subset of the language, and only use the more obscure stuff when it is actually needed(which isn't that often, but I'm glad it exists when I need it). And move semantics is not hard to understand IMO.

mlmonkey•19m ago
> If you had read like even the basic part of that article you would know that && is not a pointer to a pointer.

OK, let me ask this: what is "&&" ? Is it a boolean AND ? Where in that article is it explained what "&&" is, other than just handwaving, saying "it's an rvalue".

For someone who's used to seeing "&" as an "address of" operator (or, a pointer), why wouldn't "&&" mean "address of pointer" ?

einpoklum•17m ago
> "Whenever I'm dealing with C++" ... "I have steadfastly avoided dealing with C++"

So, basically, you're just trolling us about a language you avoid using. Thanks, that's very helpful.

Cloudflare Scrubs Aisuru Botnet from Top Domains List

https://krebsonsecurity.com/2025/11/cloudflare-scrubs-aisuru-botnet-from-top-domains-list/
43•jtbayly•2h ago•11 comments

Btop: A better modern alternative of htop with a gamified interface

https://github.com/aristocratos/btop
129•vismit2000•3h ago•86 comments

C++ move semantics from scratch (2022)

https://cbarrete.com/move-from-scratch.html
36•todsacerdoti•5d ago•19 comments

AI benchmarks are a bad joke – and LLM makers are the ones laughing

https://www.theregister.com/2025/11/07/measuring_ai_models_hampered_by/
172•pseudolus•4h ago•83 comments

An Algebraic Language for the Manipulation of Symbolic Expressions (1958) [pdf]

https://softwarepreservation.computerhistory.org/LISP/MIT/AIM-001.pdf
31•swatson741•3h ago•3 comments

52 Year old data tape could contain Unix history

https://www.theregister.com/2025/11/07/unix_fourth_edition_tape_rediscovered/
49•rbanffy•2h ago•13 comments

Driver livestreams on TikTok as she apparently hits and kills man in Chicago

https://www.theguardian.com/us-news/2025/nov/08/tiktok-live-stream-fatal-crash-chicago
24•c420•1h ago•14 comments

Why is Zig so cool?

https://nilostolte.github.io/tech/articles/ZigCool.html
447•vitalnodo•19h ago•366 comments

Valdi – A cross-platform UI framework that delivers native performance

https://github.com/Snapchat/Valdi
412•yehiaabdelm•18h ago•161 comments

Making Democracy Work: Fixing and Simplifying Egalitarian Paxos

https://arxiv.org/abs/2511.02743
115•otrack•11h ago•34 comments

Ticker: Don't Die of Heart Disease

https://myticker.com/
185•colelyman•3h ago•157 comments

Syntax and Semantics of Programming Languages

https://homepage.cs.uiowa.edu/~slonnegr/plf/Book/
10•nill0•1w ago•0 comments

Friendly attributes pattern in Ruby

https://brunosutic.com/blog/ruby-friendly-attributes-pattern
84•brunosutic•5d ago•47 comments

My friends and I accidentally faked the Ryzen 7 9700X3D leaks

https://old.reddit.com/r/pcmasterrace/comments/1orc6jl/my_friends_and_i_accidentally_faked_the_ry...
229•djrockstar1•7h ago•59 comments

Computational Complexity of Air Travel Planning (2003) [pdf]

http://www.ai.mit.edu/courses/6.034f/psets/ps1/airtravel.pdf
37•arnon•4d ago•1 comments

Reverse engineering a neural network's clever solution to binary addition (2023)

https://cprimozic.net/blog/reverse-engineering-a-small-neural-network/
48•Ameo•4d ago•11 comments

Myna: Monospace typeface designed for symbol-heavy programming languages

https://github.com/sayyadirfanali/Myna
335•birdculture•1d ago•162 comments

Cekura (YC F24) Is Hiring

1•atarus•6h ago

The modern homes hidden inside ancient ruins

https://www.ft.com/content/5f722a2e-71d8-430c-a476-95de2c4ad9a5
5•Stratoscope•5d ago•1 comments

Always Be Ready to Leave (Even If You Never Do)

https://andreacanton.dev/posts/2025-11-08-always-ready-to-leave/
32•andreacanton•7h ago•7 comments

Immutable Software Deploys Using ZFS Jails on FreeBSD

https://conradresearch.com/articles/immutable-software-deploy-zfs-jails
138•vermaden•18h ago•40 comments

How did I get here?

https://how-did-i-get-here.net/
270•zachlatta•22h ago•53 comments

Why I love OCaml (2023)

https://mccd.space/posts/ocaml-the-worlds-best/
364•art-w•1d ago•259 comments

Dark mode by local sunlight (2021)

https://www.ctnicholas.dev/articles/dark-mode-by-sunlight
30•gaws•5d ago•38 comments

Mullvad: Shutting down our search proxy Leta

https://mullvad.net/en/blog/shutting-down-our-search-proxy-leta
164•holysoles•17h ago•114 comments

The Initial Ideal Customer Profile Worksheet

https://www.reifyworks.com/writing/2023-01-30-iicp
75•mrbbk•5d ago•8 comments

Cerebras Code now supports GLM 4.6 at 1000 tokens/sec

https://www.cerebras.ai/code
147•nathabonfim59•18h ago•96 comments

Nubeian Translation for Childhood Songs by Hamza El Din

https://nubianfoundation.org/translations/
5•tzury•6d ago•2 comments

YouTube Removes Windows 11 Bypass Tutorials, Claims 'Risk of Physical Harm'

https://news.itsfoss.com/youtube-removes-windows-11-bypass-tutorials/
799•WaitWaitWha•21h ago•341 comments

Apple is crossing a Steve Jobs red line

https://kensegall.com/2025/11/07/apple-is-crossing-a-steve-jobs-red-line/
482•zdw•22h ago•389 comments