Implementing Minesweeper in Pharo

My first "real" computer ran Windows 95, and like many developers, my interests in programming were rooted in gaming. Along with Hover and Mindmaze, one of the games I loved to play growing up - a game I still love to play - was Minesweeper. I've never implemented Minesweeper, but it's a pretty simple game, and since Pharo comes with an easy-to-use UI library called Morphic, it seemed like a perfect fit for my Smalltalk project!

If you want to try out my minesweeper program, you need to install Pharo, and download the changes and image files from here. After that, simply launch the Robsweeper.image file in Pharo and have fun! The source code is present in that image in the Rob-Minesweeper package; there's also a package on SmalltalkHub. If you can't get Pharo up and running, here's what the final product looks like:

Things I Learned

Whenever I program, whichever language I'm using, I try to write small, focused methods that operate on a single level of abstraction. Working with Smalltalk, with its "you don't need to know how everything works" message, really cemented that idea within my mind. I think that "you don't need to know how everything works" is a mantra that I, and many other programmers, can probably benefit from keeping in the backs of our minds.

Things I Would Change

Since this is just a one-off project to play with Smalltalk/Pharo, not much attention was paid to code quality or organization. In fact, I think that some the cons I encountered with the language were due to unidiomatic code. Some of this was feeling my way around in an unfamiliar language and environment; some this was due to wanting to be done with the project. However, some of this was not having tests to verify that I didn't break something during a refactor. Which brings me to my next point...

If I were to write the application all over again, I would embrace the venerable Smalltalk tradition of testing and write the application using TDD principles. One of the reasons I didn't do this, even though the material I was reading talked about the cultural significance of testing in Smalltalk, is because it wasn't too clear to me how to test Morphic applications. Perhaps I should have had the Morphic components be thin wrappers over game logic classes and tested the latter; however, from my limited experience with Smalltalk, it appeared to be pretty common to incorporate the application logic directly within the Morphic classes.

Going Further with Smalltalk

As mentioned in my previous post along with its comments, I don't know if I really fully grasped the OO enlightenment that many say comes with Smalltalk; I'm guessing it comes from more than writing a single application and playing with the language for a few hours! I have some more thoughts on this, but they'll have to wait for another blog post.

I don't think this will be my only foray into the land of Smalltalk; here are some things I would like to try the next time I visit:

Published on 2016-06-26