Re:C implementation of Tic-Tac-Toe in a single call to printf
by hugomg on Sunday June 07, 2020 @10:46AM
(#23447701)
If you are curious, this is what the resulting format string looks like after expanding all the macros:
https://gist.github.com/hugomg/73e91ebca7ced3c5c6f955e9e830b...
Re:C implementation of Tic-Tac-Toe in a single call to printf
by coliveira on Sunday June 07, 2020 @12:20PM
(#23448421)
The 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.
Re:C implementation of Tic-Tac-Toe in a single call to printf
by ufo on Sunday June 07, 2020 @02:57PM
(#23449676)
Another reason is that this was intended as an IOCCC submission and IOCCC has a file size limit.
Re:C implementation of Tic-Tac-Toe in a single call to printf
by russfink on Sunday June 07, 2020 @09:14AM
(#23447097)
One time, I had to maintain C code That somebody had #define'd to look like FORTRAN. It was impressive.
Re:C implementation of Tic-Tac-Toe in a single call to printf
by gamegoblin on Sunday June 07, 2020 @03:56PM
(#23450233)
Much 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
Re:C implementation of Tic-Tac-Toe in a single call to printf
by bondarchuk on Sunday June 07, 2020 @06:12PM
(#23451360)
Quite 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?
Re:C implementation of Tic-Tac-Toe in a single call to printf
by gmfawcett on Sunday June 07, 2020 @06:25PM
(#23451485)
Might have been this. The style is usually attributed to Arthur Whitney:
Re:C implementation of Tic-Tac-Toe in a single call to printf
by simias on Sunday June 07, 2020 @09:30AM
(#23447195)
I'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.
Re:C implementation of Tic-Tac-Toe in a single call to printf
by TeMPOraL on Sunday June 07, 2020 @04:25PM
(#23450485)
I 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.
Re:C implementation of Tic-Tac-Toe in a single call to printf
by Gene_Parmesan on Sunday June 07, 2020 @02:16PM
(#23449353)
Wouldn'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.
Re:C implementation of Tic-Tac-Toe in a single call to printf
by keitmo on Sunday June 07, 2020 @04:03PM
(#23450306)
"The determined Real Programmer™ can write FORTRAN in any language."
Re:C implementation of Tic-Tac-Toe in a single call to printf
by a1369209993 on Sunday June 07, 2020 @09:06PM
(#23452574)
Real 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.)
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.