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.

8 of 68 comments (clear)

  1. proves the old maxim by Anonymous Coward · · Score: 2, Insightful

    About semi-complex programs ending up re-implementing aspects of lisp or smalltalk-- just less elegantly.
    I think you've done it!

  2. 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.

  3. 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."
  4. 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."
  5. Re:Terrifying. by SirSlud · · Score: 2, Insightful

    I am mystified how people can read this and not realize it was just a little fun thing to do in his spare time. Or do you spend every waking minute of your life doing serious things with your knowledge and skills?

    --
    "Old man yells at systemd"
  6. Re:Stupid and bad coder. by Anonymous Coward · · Score: 2, Insightful

    Go fuck yourself. Really. If you don't realize that this is a toy and a very clever one at that, I'm not sure what to tell you. Sometimes some things are done to scratch an itch, or for fun or something. You can learn an awful lot about how to do things/not do things by playing around with projects like this. Oh right, you are a "serious professional programmer" with ZERO passion for the work you do.

    Also you seriously have zero sense of humor. You must be great fun at parties.

  7. Re:Terrifying. by Cafe+Alpha · · Score: 1, Insightful

    Nonsense.

    No one should ever have to work with C++ metaprogramming in their work.

    It should not be encouraged. It's a horrible dead end. Sadly it isn't the only dead end in computer science.

  8. Re:Terrifying. by phantomfive · · Score: 3, Insightful

    Then why would they blog about it... and then submit an article to Slashdot describing and linking to their own god dam blog.

    Because other people like to see it, and it's really cool. Specifically, if you don't like this kind of thing, you shouldn't be on Slashdot. See also this.

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