Live data from Hacker News

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

news.ycombinator.com

371–380 of 394 posts

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

#371
post #215
post #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...

Perl version if you don't have a BASIC interpreter handy: perl -C -e 'print chr(9585.5+rand) while 1'

  Wide character in print at -e line 1.

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

#372

Bash fork bomb (do not run, this will crash your system if it's not configured properly): :(){ :|:& };:

...and it smiles at you with its multiple faces

Faces I can interpret:

    :(   #sadface
    :()  #dopefish
    { :  #smiling one-toothed vampire
    { :| #blank stare with hat
    :|   #blank stare without hat
    |:   #other blank stare without hat
    |:&  #blank stare with bow
    };   #winking face with mustache
    };:  #winking four-eyed alien face with mustache
Only one of those was a smile, and you generally don't want a vampire smiling at you even if they're down a tooth! ;)

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

#374
post #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...

If we define "elegant" as getting a lot done with a little, another BASIC (kinda..) one: https://linusakesson.net/scene/a-mind-is-born/ (The last part of the song is so great, too.)

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

#375
post #215

Earlier quoted context omitted.

Perl version if you don't have a BASIC interpreter handy: perl -C -e 'print chr(9585.5+rand) while 1'

Wide character in print at -e line 1.

Oh, Windows maybe? add:

binmode(STDOUT);

To the front.

Unicode on languages made before it existed is...argh.

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

#376
post #220

Earlier quoted context omitted.

Oh man, PC Logo takes me back down the memory lane. We were introduced to PC Logo in 4th grade, that's about 9 years ago. I instantly fell in love with it. The amount of power I had over the computer - ordering it to draw what I want, how I want was really exciting. My father had installed Kubuntu on our home computer which had an amazing suite of educational applications, including KTurtle which was (almost) the sam…

I clicked on your blog and all the images are gray exclamation marks :(

Yeah, the images got corrupted or lost in Google's servers somehow some time around 2013. Couldn't get them back :/

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

#377
post #220

Earlier quoted context omitted.

I clicked on your blog and all the images are gray exclamation marks :(

Wayback Machine to the rescue: https://web.archive.org/web/20121023081714/https://kturtleco... I recommend adding bookmarklets for Wayback Machine: https://en.wikipedia.org/wiki/Help:Using_the_Wayback_Machine...

Thanks for this! But it none of the saved webpage seem actually saved or clickable.

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

#378
post #348

Earlier quoted context omitted.

I'm amazed that you're defending that comment.

Well, I am amazed that one can be so rude. First, you come blazing with accusations of transphobia, because of a joking mention of Thailand's ladyboy scene, to challenge the parents' notion that everything is WYSIWYG. Do you even know me? Or you have a hobby of randomly assuming things about people you don't know? Second, when I don't take that quietly, you add the above comment about having the gal to defend myself,…

Good on you for standing for what you say. I personally didn't see any transphobia in your comment, what you said is merely a joke on a fact of that part of the world. The "phobia" was added on by Zhyl

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

#379

Earlier quoted context omitted.

The size of the buffer pointed to by s may be larger than the current string it holds. It may also be uninitialized.

Or point to the wrong thing, or point to unmapped memory, or be const, or…there's a lot of things that can go wrong with this function.

The things I listed are things the function does right as written but could not do if it worked the way suggested above.

The things you listed are general concerns in C which are unrelated to both the correct implementation and the suggested changes.

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

#380

Earlier quoted context omitted.

The size of the buffer pointed to by s may be larger than the current string it holds. It may also be uninitialized.

That’s what strncpy() is for

No, it's not. strcpy is fine to use if the destination buffer is larger than you need or uninitialized. That's idiomatic...
Post reply on HN