in ,

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


            
            

                  

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 []=[]     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 atruequicksort [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 functional code can be clean.

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

            
            
            

                  

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!)

            
            

                  

This is still one of my favorites. In a list of magic numbers, sorted by magic-ness, 0x5F 3759 DF would sit pretty high.

            

*****************

                  

The 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.

            
            

                  

It’s a bit of a tricky question because you can have a beautiful snippet entangled in a mess of a codebase.

I think a much better question would be most beautifully structured

Code, as a snippet, or line, is constantly struggling between poetic conciseness and verbose clarity … To which I will always pick clarity (for “the next guy”), hence not necessarily elegant.

            

                  

>I think a much better question would be most beautifully structured codebase.

That would be an interesting thread too! I think gorgeous snippets have a different kind of beauty that just generally well done projects.

To me, it’s kind of like comparing the beauty of a gem to the beauty of a bridge.

            
            
            
            

                  

My first language was QBASIC and much of the first code I read (other than modifying PHP scripts I didn’t really understand) was from Pete’s QB Site. I’d hardly call it beautiful, but definitely nostalgic and cool.

            
            
            
            

                  

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.

            

                  

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.

Brave Browser
Read More
Payeer

What do you think?

Leave a Reply

Your email address will not be published.

GIPHY App Key not set. Please check settings

Katie Hill, rising Democratic star, resigns amid claims of relationship with staffer – The Guardian, Theguardian.com

Katie Hill, rising Democratic star, resigns amid claims of relationship with staffer – The Guardian, Theguardian.com

Ask HN: What do you automate in your life and work ?, Hacker News