Live data from Hacker News

The Most Beautiful Piece of Code That Prints 42

fluentcpp.com

21–24 of 24 posts

Re: The Most Beautiful Piece of Code That Prints 42

#21
post #7

#include #define SIX 1+5 #define NINE 8+1 int main(void) { printf("%d * %d = %d\n", SIX, NINE, SIX * NINE); return 0; } https://github.com/Keith-S-Thompson/42

Ever waste days debugging a subtle bug introduced by C macros? It's PTSD material. I love C but I will never understand why C has a naive macro system.

The kenc[1] compiler subsequent to K&R C had much more constrained macro system exactly for those reasons. Thanks to advances in optimization and improved machine speed, it was reasonable to skip preprocessor-level const operations. Thanks to dead code elimination it was feasible to mostly give up conditional compilation.

[1] as used, for example, in Plan 9.

Re: The Most Beautiful Piece of Code That Prints 42

#22
post #3

Like most code, this is way too easy in Perl 6. > perl6 -e 'say "Life, the Universe and Everything".WHY' 42

For non perl users - does this really work or are you being ironic?

https://github.com/rakudo/rakudo/blob/master/src/core/Str.pm...

Oh, it works.

Re: The Most Beautiful Piece of Code That Prints 42

#23
post #22

Earlier quoted context omitted.

For non perl users - does this really work or are you being ironic?

https://github.com/rakudo/rakudo/blob/master/src/core/Str.pm... Oh, it works.

Today I learned about meta methods. Thanks :)

Re: The Most Beautiful Piece of Code That Prints 42

#24
post #3

Like most code, this is way too easy in Perl 6. > perl6 -e 'say "Life, the Universe and Everything".WHY' 42

For non perl users - does this really work or are you being ironic?

I searched for a Perl6 repl to try it on and it works! Perl is so whimsically fun. :)

https://tio.run/#perl6

Post reply on HN