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…
Ask HN: What is the most beautiful piece of code you've ever read?
31–40 of 394 posts
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#32https://github.com/achael/eht-imaging This python code was part of the imaging, analysis, and simulation software for radio interferometry that led to the historical first 'image' of a black hole.
What about the code did you find so striking? Any part in particular you recommend checking out?
It's utterly digestable due to its use of meaningful variable names, logical breakdown of functions and absence of 'clever' nontrivial one-liners.
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#33I can remember the first code that showed how to exploit IFS, race conditions via symlink, the classic "smashing the stack", RTM's worm.
Beauty of a code to me has nothing to do with the formatting, comments, documentations, but everything to do with the mind that bent it into place. Most of the beautiful code I have ever seen would be classified as ugly, spaghetti, not production worthy.
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#34The 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…
Having said that, it is elegant and clean and -- taken by itself -- does make Haskell very attractive.
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#35The SQLite source tree and DRH code in general are truly piece of art. Almost every line of code is carefully commented. Despite the complexity of the project, you'll learn a lot of practical concepts including expression tree generation, bytecode execution, how to test your code and so forth.
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#36For 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.
Deleting code is a beautiful feeling. Python's new walrus operator has gotten a lot of hate recently, but a few days ago I was writing a script and realized I could get rid of a few lines (AND have my meaning be clearer) using the walrus operator. So satisfying.
I do, however, resent Python 3 for removing pattern matching on tuples in function heads.
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#37For 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?
#38Curious 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?
Re: Ask HN: What is the most beautiful piece of code you've ever read?
#39For 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?
#40Curious 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?