
Tetris as a C++ Template Metaprogram - ScottWRobinson
http://blog.mattbierner.com/stupid-template-tricks-super-template-tetris/
======
paulasmuth
I am not sure if I should be amazed or scared by this. Guess it won't be long
before somebody comes up with the only thing left to do, going full meta and
writing a "c++ to c++ templates compiler" (or something along those lines).

Now if only we had a way to use all this goodness to reflect on
structs/enumerate members...

On the actual topic: I wonder how much memory it takes to compile a single
round of tetris?

~~~
emillon
This kind of compiler has already be done:
[http://gergo.erdi.hu/projects/metafun/](http://gergo.erdi.hu/projects/metafun/)

~~~
paulasmuth
Amazing. Maybe we are onto a new kind of Rule 34 here...

"Everything that can be implemented in {c++ templates, javascript} will
eventually be implemented in that language"

~~~
abhorrence
Atwood's Law: "Any application that can be written in JavaScript, will
eventually be written in JavaScript."

~~~
paulasmuth
That's hilarious -- in fact the full quote is even better. This guy hits it
right on the nose:

jeff atwood: "any application that can be written in JavaScript, will
eventually be written in JavaScript. Writing Photoshop, Word, or Excel in
JavaScript makes zero engineering sense, but it's inevitable. It will happen.
In fact, it's already happening"

Good foresight considering he said this 2009.

~~~
oldmanjay
Of course, it doesn't make "zero" engineering sense in any logical fashion.
Only those emotionally distraught by the "imperfection" of JavaScript don't
see the utility in applications moving to the web.

Which isn't to say the web is ready. But it will be!

~~~
JoshTriplett
Thankfully, "moving to the web" no longer means JavaScript; WebAssembly can
support that kind of thing instead, using arbitrary languages.

Also, you say "emotionally distraught" as though there's no _technical_ reason
to dislike JavaScript.

~~~
oldmanjay
There are technical reasons to dislike literally every technology. I say
"emotionally distraught" because JavaScript seems to attract detractors who
think that strong feelings are a valid substitute for logic.

------
gpvos
Since jwz said "every program attempts to expand until it can read mail", the
only thing we still need is a mail reader in C++ templates.

------
avodonosov
In lisp it's much easier to do, just write normal tetris and call it at
compile-time via macro.

~~~
paulasmuth
Pics or it didn't happen ;) /jk

On a serious note: modern C++ does have const expression functions, too,
albeit not as powerful (yet):
[http://www.cprogramming.com/c++11/c++11-compile-time-
process...](http://www.cprogramming.com/c++11/c++11-compile-time-processing-
with-constexpr.html)

~~~
TeMPOraL
No need for pics, it's the thing about Lisps that you can run arbitrary code
during compilation. The distinction between compile-time and runtime is pretty
blurred, especially that Lisp programs tend to ship with the compiler in the
image, which means you can compile new stuff at runtime.

~~~
paulasmuth
I realize that. I was joking [more like trying to, it seems] about the fact
that parent commented on a technically amazing post with "I could have done
this too in X" without providing any further insight, let alone a link to the
completed project in X.

~~~
TeMPOraL
Fair enough :). Though I interpret that parent comment not as bragging, but as
making a joke that in Lisp you write the program as you would normally, and
then just make it run in compile-time :).

------
codeshaman
This is so cool and so totally and entirely useless that it had to be done.
Bravo !

------
amelius
C++ template metaprogramming is turing complete. So why not write a simple
compiler that targets it. Then you can write any program as a template
metaprogram.

~~~
zem
been done:
[http://gergo.erdi.hu/projects/metafun/](http://gergo.erdi.hu/projects/metafun/)

------
moron4hire
I could have sworn I saw a guy do this over at gamedev.net in 2003. I can't,
for the life of me, find it.

~~~
Aardwolf
Do you maybe mean this? :D
[http://web.archive.org/web/20030309013522/http://www.gamedev...](http://web.archive.org/web/20030309013522/http://www.gamedev.net/columns/hardcore/tetris/)

~~~
moron4hire
Yeah, I remember that specific code (I even remember when it was written, it
was quite a good time for all the chaps), but I know that wasn't the template
metaprogramming version. Perhaps I'm just remembering a later conversation
where we discussed the concept that C++ templates were Turing-complete and
thus Tetris _could_ be made, then someone jokingly linked to this.

------
whoseking
This is evil

