Skip to content

Comment on Ask HN: What's the most elegant piece of code you've seen?

Comments

C string copy.

    while (*p++ = *q++);

Interestingly, I consider that deeply inelegant. But it sure is concise.

It's all in how one defines "elegant", I suppose. It relies on a handful of almost side-effects and the lucky confluence of a series of unrelated language choices; I see this and it reminds me of a dance, someone seeing the swinging pieces of the code and making a minor touch in just the right place, taking advantage of edge-effects that were never designed for exactly this but combine to make something emergent so simple and easy. I see this as breathtakingly elegant.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.