# App Academy Diary, Week Two

Originally published: 2013-09-23
Canonical URL: /2013/Sep/app-academy-diary-week-two/

_Monday 23 September 2013_— I rewrote most of the tic-tac-toe game yesterday; information-theoretically speaking, the board state is only 9 lg 3 ≈ 14.26 bits, but for better or for worse, I resisted the temptation to represent it as a two-character string. Still (still!) didn't get the AI working, though. Today was our first assessment: way too easy, I thought; we were given about an hour, and I finished in under half that. Then we had a lecture/Q&A period which I thought was too long, which covered the solutions to the assessment and default hash values. Why does anyone think lectures are a good idea? I'll confess to hanging out in the back and reading a little bit from _A Farewell to Alms_, which I bought on a whim on Saturday at Half-Price Books (which is a nice store, although you have to wonder whose idea it was to stock so many copies of _Elliptic Partial Differential Equations and Quasiconformal Mappings in the Plane_). At lunch I bought coffee and food at Starbucks and spent a little more time trying to debug the tic-tac-toe AI—_still_ to no avail, but I'll get there eventually! (Tic-tac-toe itself is dross, but it's really important to get minimax right, because it should generalize to other games without _too_ much trouble, and we're doing chess later this week.) _Speaking_ of games on grids, today's project was to clone Minesweeper. I worked with [_Jeff Fiddler_](https://github.com/jeffnv), who is the Jeff from Nevada (and not the other Jeff who tried to teach math in high schools but was frustrated with the overemphasis on standardized tests). It went really well; we used pretty Unicode symbols and even got around to implementing a cursor interface (which is way better than making the user enter coordinates)!

_Wednesday 25 September 2013_— Yesterday and today I wrote chess with _Nathan Holland_! Also, it turns out that the criminal scum who steal entire bicycles are not above stealing individual wheels, either.

[![Our Chess]({static}/images/our_chess.png)]({static}/images/our_chess.png)

_Thursday 26 September 2013_— Today's exercise was to write checkers, alone (contrast to the pair programming methodology of previous days). I ... used [structs](http://www.ruby-doc.org/core-2.0.0/Struct.html) to represent the checkers and moves? I like structs?

[![My Checkers]({static}/images/my_checkers-275x300.png)]({static}/images/my_checkers.png)

_Saturday 28 September 2013_— Yesterday was about _testing_. Novice programmers test their programs by running them and seeing if they give the expected results, which might be okay when your program is small and no one actually uses it, but then what happens when you wake up one day and you're in charge of maintaining a twenty-thousand-line application that people really depend on?

Enter automated testing. By writing code to test code, developers can save time and be confident that recent changes haven't broken existing functionality! (At this point a pedant smugly inquires whether this implies the necessity of writing tests for the tests, and tests for the test-testing tests, and so on _ad infinitum_. This arguably doesn't deserve a reply, but is in any case easily answered by the observation that we expect tests to be much simpler than the code which is their subject; it takes less information to specify what is expected of a procedure than it does to specify the details of the procedure itself.) In _test-driven development_, the practice is actually to write the tests _first_.

I paired with [_A. J. Gregory_](http://aj-gregory.tumblr.com/); after some simple exercises, our major task of the day was to write a five-card-draw poker game in the test-driven development style. I will confess that this did not go as successfully as the projects of previous days. Perhaps the art of factorizing the idea of a program into informative tests takes more than a day to learn? Or maybe we were succumbing to tiredness at the end of a very educational week, this fatigue being only a very minor sin characteristic of being human, for which we may yet be forgiven? I can't say. (Yet.)

_Sunday 29 September 2013_— Dear reader, suppose you're on a quest to write the Great American Web Application—maybe the latest, greatest dog-sharing site or something; I don't know. Your app is going to need some way to persistently store data—your users' screennames, emails, hashes of their passwords ([use bcrypt](http://codahale.com/how-to-safely-store-a-password/)!), their dogs to share, _&c_. This data isn't really part of your application proper, so it goes in a special separate file called a database, but it _is_ that which your application operates on and fundamentally exists for the sole purpose of curating, so your app needs some way of talking to the database and asking it questions, like "Hey, Database! User #97109 wants to be friends with User #89012; write that down, huh?" or, "My dearest friend Database, when you have a moment, could you please tell me which dogs User #98471 has available to share?" But this is mere anthropomorphism; what protocol do you actually use to get your code to talk to the database? If only there were some _standard vocabulary_ for asking questions of the database ... some sort of—_systematic questioning lexicon_ ...

Right, so today I successfully installed MySQL after some troubleshooting effort (it turned out that I needed to apt-get the [mysql-server](http://packages.ubuntu.com/raring/mysql-server) metapackage, and not [mysql-server-core-5.5](http://packages.ubuntu.com/raring/mysql-server-core-5.5)), and got acquainted with it at the command-line. Data is organized into _tables_ of columns and rows, like maybe we have a `ponies` table with columns for `pony_id`, `name` and `pony_type`, and one of the rows is `2 | Twilight Sparkle | unicorn`, and if we want to update Twilight's type we say, "`UPDATE ponies SET pony_type = 'alicorn princess' WHERE pony_id = 2`" and if we want to just look at the earth ponies we say, "`SELECT * FROM ponies WHERE pony_type = 'earth pony'`".
