Live data from Hacker News

Ask HN: What is the most beautiful piece of code you've ever read?

news.ycombinator.com

21–30 of 394 posts

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#21

Any of Norvig's notebooks, http://www.norvig.com/ipython/README.html , especially his Concrete Introduction to Probability https://nbviewer.jupyter.org/url/norvig.com/ipython/Probabil... .

Oh my God, his Lisp interpreter in Python: amazing. At the time I was just getting a grip with Python and starting in Lisp, it came at just the right moment in my autodidaction.

Really really good, although for a lot of people here it might be a little elementary (but then, the best code always feels elementary even when doing something advanced!)

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#22
post #6

For me, the answer is - The code that never existed. Not to sound cheeky but eliminating code, is a beautiful thing. Less code is easier to maintain, understand, and faster to run. So the less code you can achieve, the better overall the software will be.

> For me, the answer is - The code that never existed.

> Not to sound cheeky but eliminating code, is a beautiful thing. Less code is easier to maintain, understand, and faster to run. So the less code you can achieve, the better overall the software will be.

Unless you think compressed/ minified code is beautiful, there must be additional factors involved other than minimizing LoC.

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#23
For me it's a BASIC one-liner which generates mazes

  10 PRINT CHR$ (205.5 + RND (1)); : GOTO 10
I found this specific one via slashdot[1], but something similar, which I've never managed to find/replicate, was used to generate mazes on the Atari 800 XL at my school when I was a kid.

[1] https://developers.slashdot.org/story/12/12/01/1847244/how-d...

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#24
The one that blew my mind when I was in college was a simplified version of quicksort in Haskell. It's just so elegant and clean.

    quicksort :: Ord a => [a] -> [a]
    quicksort [] = []
    quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
        where
            lesser = filter (= p) xs
Now surely someone may come along and point out how this isn't a true quicksort[0] because it doesn't partition the elements in place, but it's more of the simplicity of the logic and its readability that showed me how beautiful functional code can be.

[0] https://stackoverflow.com/questions/7717691/why-is-the-minim...

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#25
post #6

For me, the answer is - The code that never existed. Not to sound cheeky but eliminating code, is a beautiful thing. Less code is easier to maintain, understand, and faster to run. So the less code you can achieve, the better overall the software will be.

> For me, the answer is - The code that never existed. > Not to sound cheeky but eliminating code, is a beautiful thing. Less code is easier to maintain, understand, and faster to run. So the less code you can achieve, the better overall the software will be. Unless you think compressed/ minified code is beautiful, there must be additional factors involved other than minimizing LoC.

To me it's removing lines of code without affecting readability (or even improving it). Like when you don't know about a language feature so you implement a hacky version, then find out there's already a very elegant standard way to do it so you get to lance that hideous monstrosity you made off your code

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#27

Quicksort in Haskell is very elegant, though not truly quicksort (not sort in place): https://wiki.haskell.org/Introduction#Quicksort_in_Haskell

You are the second person to reference quicksort in Haskell in this thread. The other person even mentioned it not being true quicksort. Who knew quicksort in Haskell was such a beloved piece of code!

Re: Ask HN: What is the most beautiful piece of code you've ever read?

#30

Any of Norvig's notebooks, http://www.norvig.com/ipython/README.html , especially his Concrete Introduction to Probability https://nbviewer.jupyter.org/url/norvig.com/ipython/Probabil... .

Oh my God, his Lisp interpreter in Python: amazing. At the time I was just getting a grip with Python and starting in Lisp, it came at just the right moment in my autodidaction. Really really good, although for a lot of people here it might be a little elementary (but then, the best code always feels elementary even when doing something advanced!)

IMHO, the most beautiful lisp interpreter in a language that is not lisp is this one in prolog.

https://www.metalevel.at/lisprolog/ https://www.metalevel.at/lisprolog/lisprolog.pl

Post reply on HN