4 ms·
Oddly enough I find that the #define macro soup detracts from the performance here. I was rather unimpressed at first because obfuscating C code by just #define
by simias 6y ago
Oddly enough I find that the #define macro soup detracts from the performance here. I was rather unimpressed at first because obfuscating C code by just #define'ing a bunch of code is a trivial and rather uninteresting way to write unreadable code. Of course you can make any arbitrary code look like a printf call with enough macros!
But it's actually a lot more clever than that.
I feel like this would be a lot more impressive if it was written in simple and clear C since then you'd see that there really isn't any tic-tac-toe logic being explicitly implemented the way you'd expect.
- russfink 6y agoOne time, I had to maintain C code That somebody had #define'd to look like FORTRAN. It was impressive.
- simias 6y agoI've had to deal with code like that, only poorly mimicking Lisp instead: `#define unless(_x) if (!(_x))` etc... One of my favourite accidental features in Rust is that macros are so annoying and cryptic to write that people think twice before abusing them.
- Gene_Parmesan 6y agoWouldn't be surprised if that was intentional, actually. The idea of making syntax a little unwieldy for things that you should really think twice before using is not a new one.
- TeMPOraL 6y agoI understand the temptation. I keep catching myself on writing `unless( ... )` in C++ every couple days, and I've considered adding a macro for it, but ultimately decided against it, as the rest of the team would not understand why I need it.
- codezero 6y agoOne time, I had to maintain FORTRAN code. Much of it was still in FORTRAN 66.
- gamegoblin 6y agoMuch of the original Bourne shell was written in C that had been macro'd to look like Algol [1]. E.g. /usr/src/cmd/sh/mac.h: #define IF if( #define THEN ){ #define ELSE } else { #define ELIF } else if ( #define FI ;} #define BEGIN { #define END } #define SWITCH switch( #define IN ){ #define ENDSW } #define FOR for( #define WHILE while( [1] https://research.swtch.com/shmacro https://research.swtch.com/shmacro
- bondarchuk 6y agoQuite some time ago I saw a piece of C code (probably linked from here) in APL style, I have been trying to find it since, does anyone know what I mean?
- gmfawcett 6y agoMight have been this. The style is usually attributed to Arthur Whitney: https://code.jsoftware.com/wiki/Essays/Incunabulum https://code.jsoftware.com/wiki/Essays/Incunabulum
- keitmo 6y ago"The determined Real Programmer™ can write FORTRAN in any language."
- a1369209993 6y agoReal Programmers write machine code in any language, thank you very much. (Which TFA rather nearly is, actually, though it's a bit macro-assemblery for a proper example.) http://www.catb.org/jargon/html/story-of-mel.html http://www.catb.org/jargon/html/story-of-mel.html
- hugomg 6y agoIf you are curious, this is what the resulting format string looks like after expanding all the macros: https://gist.github.com/hugomg/73e91ebca7ced3c5c6f955e9e830b636 https://gist.github.com/hugomg/73e91ebca7ced3c5c6f955e9e830b...
- coliveira 6y agoThe reason he had to use macros is that the actual formatting string is huge and difficult to understand. In this case, macros really serve a useful purpose, instead of just obfuscating code.
- ufo 6y agoAnother reason is that this was intended as an IOCCC submission and IOCCC has a file size limit.
- voldacar 6y agoThe macros are a form of data compression. Otherwise the string would be absurdly huge