:(){ :|:& };:Ask HN: What is the most beautiful piece of code you've ever read?
41–50 of 394 posts
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#42Quicksort 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!
This wasn't the only case I noticed of highly-rated broken code there. It took me a long time to take this lesson to heart about especially slick-looking code of my own.
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#43https://m.youtube.com/watch?v=HxaD_trXwRE
A good debuggable piece of code explains what it is trying to do by being clearly written and conforming to a consistent and logical model. I don’t think I would ever have invented this type of lexer pattern in Go by myself, but would be very grateful to come across it in a code base I had to fix. Like Duff’s Device mentioned in this thread, it has just the right amount of cleverness without becoming inscrutable.
Also, if you’ll excuse some avuncular pride, my niece and I wrote some code yesterday. She asked me how many times grandma’s clock chimes every day and we ended up with the following Ruby:
2 * (1..12).reduce(&:+)Re: Ask HN: What is the most beautiful piece of code you've ever read?
#44Re: Ask HN: What is the most beautiful piece of code you've ever read?
#45Lexical Scanning In Go is a charming piece of programming: https://m.youtube.com/watch?v=HxaD_trXwRE A good debuggable piece of code explains what it is trying to do by being clearly written and conforming to a consistent and logical model. I don’t think I would ever have invented this type of lexer pattern in Go by myself, but would be very grateful to come across it in a code base I had to fix. Like Duff’s Device m…
Python: 2 * sum([x for x in range(1, 13)])
Haskell: 2 * sum [1..12]
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#46 void strcpy(char *s, char *t) {
while (*s++ = *t++);
}
It's short, elegant, and quite readable to the trained eye–a bit sharp too, but if you use it right it's quite functional.Re: Ask HN: What is the most beautiful piece of code you've ever read?
#47Re: Ask HN: What is the most beautiful piece of code you've ever read?
#48John Carmack's Fast Inverse Square Root: https://en.wikipedia.org/wiki/Fast_inverse_square_root#Overv... . The first time I really and truly felt that people approach problems differently from how I, by default, go about them.
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#49Curious why the comment about STL algorithms written by Alexander Stepanov was downvoted so hard it died? I’m not a C++ dev... is he hated or is the implementation that bad?