Settings

Theme

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

15 points by Dopameaner · 8 comments · 1 min read


old - https://news.ycombinator.com/item?id=11005003

Been a while since this was asked. What has captured your attention for its elegance and beauty

8 threads
_-----_

Anything I have ever written, until I've re-read it.

jeffrallen

A wonderfully Go-like piece of magic: https://github.com/golang/go/blob/go1/src/pkg/image/gif/read...

What's magic there seemed magical at the time because even Go's creators were only just coming to see the power of interfaces then. Now, having a decompressor read from a block reader, which reads in turn from some other place, is not magical, it's just good practice.

This is from Go 1. Unfortunately, that file accumulated tons of other ugliness over time, as it dealt with the real world. I was one of the people who had to make that line less magic. Sorry Rob.

derwiki

A little dated, but tornado always impressed me:

https://github.com/tornadoweb/tornado

Also Norvig’s spell checker:

https://norvig.com/spell-correct.html

DopameanerOP

Some of my fav. works include

Bittorrent and Bitcoin

deterministic

The Lambda Calculus. Invented in the 1930s it is still used today as the basis for most advanced CS research and as the foundation of many programming languages.

betsuin

cat /var/log/apache2/access.log | awk '!a[$0]++'

DopameanerOP

I am surprised no one mentioned chatGPT or GPT-3

bitlax

Redis source often gets mentioned in these threads.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection