Yaml

May 20, 2013

App Academy W2D1

YAML

The lesson today involved opening and closing files and serialization of data to file formats like YAML (Yet Another Markup Language) and JSON. The major project that my partner and I worked on was Minesweeper, which is our version of the crappy game that you play on Windows whenever Solitaire doesn’t work.

We finished relatively early and we attribute this success to a crucial design choice that we made when we started the program. People had tried to create Minesweeper by creating classes out of the Board and the spots on the board. Then for the part where you try to figure out the numbers of bombs, they would implement an array that carried within them their fellow neighbors. This led to serious issues when they tried to print out the board because of how interconnected the objects were. Ruby would simply print ad infiniteum because of all the connections.

We did create a Square class but concentrated on implementing much of the logic regarding neighbors and rendering the board out in the Game class. We had tried this before with Tic Tac Toe with less than optimal results. However with Minesweeper, in where we create the board at the beginning of the game and with only 1 player playing it, this was a resounding success. We were able to simply create fixnum values and filling the spots with each of them. The rest of the game - including the serialization of saved games and the deserialization of saved games - came relatively easily. I have to admit that I felt a rush of exhilaration when we loaded a complete Minesweeper game from memory.

Top 4 Things I Learned Today:

1) YAML is the preferred format to save Ruby classes and they can be saved to files. Also, file extensions are BS

2) We need to call File.close because of Ruby’s buffering functions. Without file.close, the program could potentially not write data that we previously thought was written

3) Serialization is the preservation of data.

4) Modules can be used to share code between classes where Subclassing would not be the right way to do it

Other Things I Think I Think:

I took my first assessment today. It was relatively easy but I feel that that is the easiest that it is going to get. The real tough stuff is coming.

There is something amazing with watching something that we plan out in advance suddenly working on the first try. Implementing a BFS-type search to magically reveal all the cells that do not have the Adjacent Value of 0 is amazing.

Good software design does a lot.

I finally know what Paul is talking about when he blabs about JSON and YAML.