Slashdot Mirror


Clang Plays Tetris -- Tetris As a C++ Template Metaprogram

New submitter mjvzb writes: Ever wish compiling was more fun? Well, I recently implemented Tetris as a C++ template metaprogram (code at Github). The game is played by recompiling its source, taking player input by compiler flag. The runtime program is only needed to print the game screen to the console and save the game state across compiler runs.

Implementing Tetris in templates is not as horrific as you may imagine, and I've put together a post covering the details. Once you get over the syntax, C++ metaprogramming is just like functional programming.

3 of 68 comments (clear)

  1. Re:Terrifying. by Anonymous Coward · · Score: 4, Insightful

    Who are you to judge that? Maybe he was lost in the depths of suicidal depression, and this project gave him a reason to drag himself out of it. Maybe an alien race will visit the earth and think that this is just so goddamn clever that there's no reason not to share their hyperdrive tech with us. Or whatever. But basically, fuck you and don't worry about what other people choose to do or not do.

  2. Re:C++ metaprogramming is just like functional pro by phantomfive · · Score: 4, Insightful

    metaprogramming is like functional programming in these senses:

    1) Uses lots of recusion
    2) Has no variables, only constants. Nothing is mutable.
    3) Has functions

    Because of 1 and 2, it helps to think in terms of functional programming if you want to do anything substantial.

    --
    "First they came for the slanderers and i said nothing."
  3. Re:Terrifying. by phantomfive · · Score: 4, Insightful

    If only the people who want to take on challenges like this put their skills to something actually useful....... There has GOT to be a better use of your knowledge and skills.

    Sometimes people do things for fun........not because they want to please internet critics.

    --
    "First they came for the slanderers and i said nothing."