

Termtris: A Game Like Tetris in Ten Functions - tylerneylon
https://github.com/tylerneylon/termtris

======
adamesque
Whoa! Love the idea of a hybrid lua/markdown file; I didn't realize that the
readme for the Github project WAS the source code till I noticed it was just a
symlink to the .lua file.

Very cool.

~~~
elviejo
That approach is called literate programming.
[http://en.m.wikipedia.org/wiki/Literate_programming](http://en.m.wikipedia.org/wiki/Literate_programming)

~~~
theoh
This is an obvious point, but the slightly ostentatious uses of the term
"literate" by Knuth is not, apparently, a dig at the kind of "coding bums"
(Dijkstra's words) who liked to use APL. There is a literate APL system out
there, and Knuth seems to see APL in a different light from Dijkstra, as a
specification language. [http://tex.loria.fr/litte/knuth-
interview](http://tex.loria.fr/litte/knuth-interview)

~~~
dllthomas
He said he chose "literate" because he wanted those who didn't like it to be
advocating "illiterate programming".

The common use of the term these days (source interspersed with documentation,
serving as both) leaves out one significant aspect of WEB, where you could do
quite a bit of rearranging the file layout (with slightly-buffed-up C style
macros, basically) so that the communicative structure _dominated_. Reading
through the papers on it was interesting; I've not actually put together a
project in it.

------
jewel
The more flexibility a language gives you in the order you place your code,
the better it is for literate programming. If you haven't seen it yet, check
out the source code to coffeescript.

Here is the source file:
[https://github.com/jashkenas/coffeescript/blob/master/src/gr...](https://github.com/jashkenas/coffeescript/blob/master/src/grammar.coffee)

Here is a nicely rendered version of the same file:
[http://coffeescript.org/documentation/docs/grammar.html](http://coffeescript.org/documentation/docs/grammar.html)

Also see literate coffeescript, a mode that seamlessly integrates markdown.
I'd give up vim for a environment that lets me embed images, embed SVG
diagrams, use those SVG diagrams at compile time to generate code, etc.

~~~
kazinator
It's a nice sentiment there in your last sentence, but good luck with your git
repo, merging parallel changes from multiple developers to your compilable SVG
diagrams. :)

------
taeric
So, I am definitely a fan of literate programming. I'm not sure I am a fan of
what I will call the polyglot method, though.

Specifically, I don't think I fully grok/agree with the utility of having a
single file that is both a markdown file and a lua file through commenting. In
the end, it means you are still greatly limited to the ordering semantics of
the main language.

Which is _not_ to say some folk won't do an amazing job writing a program.
They clearly will. However, I think the macro approach of CWEB (or noweb,
even) still has a lot of mileage that is overlooked nowdays.

~~~
mhd
Totally agree, what we often see nowadays is still interesting, but mostly a
"rich text comment" style. The two main factors for this are that such
preprocessors are easier to write than weave/tangle systems, and that many
people feel that in a modern idiom this isn't needed anyway. Shorter
functions, no need for pre-declared variables, function hoisting, less global
state...

Not that this is totally wrong, working around the limitations of Pascal/C is
one reason for the way Knuth's literate programming style was developed. The
way I see it, the more simpler style is pretty good for a well-documented
program that needs to be maintained, less so for a narrative that is a bit
less focused, documenting the way something was initially written ("Let's add
another field to our wibble_wobble structure to make wonk-gibbling work
properly").

------
cpayne
As a Microsoft developer who has never looked at a terminal before, I find
these projects amazing. The OP wrote a tertis clone in terminal - clever /
cool

THEN its well documented!

THEN its in one file - wtf?

Well done!

~~~
tylerneylon
Thank you!

------
advocaat23
Pretty nice. Writing a tetris clone targeting terminals is a fun endeavor and
the easiest way to produce some moving graphics (besides Conway's Game of
Life). It's also interesting to ignore curses and read and write plain bytes
to the terminal and see what happens. I learned lots of nifty details about
terminals there and you find pages like this:

[http://www.ibb.net/~anne/keyboard/keyboard.html](http://www.ibb.net/~anne/keyboard/keyboard.html)

------
kazinator
Original Tetris for Terminals: 1989!

[http://www.miketaylor.org.uk/tech/tt/](http://www.miketaylor.org.uk/tech/tt/)

Not done in 10 functions though! C on Unix.

However, IOCCC entry in the same year:

[http://homepages.cwi.nl/~tromp/tetris.html](http://homepages.cwi.nl/~tromp/tetris.html)

------
lalunia
Like the example ~300 line tetris implementation for tinygame:
[https://github.com/nmillerns/tinygame](https://github.com/nmillerns/tinygame)
Except that uses raw prints and termios in python instead of curses

------
sebnukem2
Best documented little project ever.

------
liadmat
Cool project. It reminded me of the "Tetris in 140 bytes" project, worth a
look:
[https://gist.github.com/aemkei/1672254](https://gist.github.com/aemkei/1672254)

------
dimitar
Tetris implementation for emacs:
[http://home.pipeline.com/~hbaker1/emacs/tetris.el](http://home.pipeline.com/~hbaker1/emacs/tetris.el)

------
nebyoolae
This is a great little game and the documentation is amazing.

------
sungeuns
Wow, the document is awesome and code is really understandable though I
haven't used lua before. It's pretty nice work! thanks for sharing :)

------
dmritard96
The elegance of the block descriptions made me blush, haha. Very nice.

------
chrisweekly
This gives "self-documenting code" a whole new meaning. ;b

