Journal Entry #12
I’ve been working on the program, but not documenting progress here, for more than a week now. Sorry about that. As I’ve mentioned before, it’s hard to make a worthwhile post if you have nothing tangible to report. For a while now I’ve had the additional problem that it’s rather difficult to even describe what I’ve been working on. Basically I hit a speed bump, now that I’m (more or less) through it, I feel capable of describing it.
Basically I’ve been working on the game management features. The most important features of Tarrasch are concerned with creating and editing individual games, which means working with moves, variations and comments. But Tarrasch V2 must allow effective manipulation of whole .pgn files as well. That means a mode in which the smallest unit of information is a whole game. This is not rocket science. I offer the user a scrollable list that shows all the games in a .pgn file. The user can select a game to work with, which effectively exits the game manipulation phase and returns to the mainstream activity of working with an individual game. But of course I must provide other game manipulation features. The user can sort the games by clicking column headings. Or edit game details (players, site, tournament, date etc.) I’ve blogged about those features before.
Of course the user can select one or many games and delete, cut, copy and paste. Copy works in the conventional way, that is the clipboard is emptied immediately before the start of each copy. That can be annoying so I offer an “Add to clipboard” feature as well as copy. The other features I offer are “Save file”, “Paste current game” and “Renumber”. Obviously save file lets the user save the modified .pgn file after deleting or pasting games. Paste current game allows the user an alternative way to save a game. Normally they would use “Save” or “Save as” from the file menu. The alternative way is to open a file after creating a game from scratch and then “Past current game” into the list of games. “Renumber” allows the user to save the games in the order they appear on screen (typically after a sort) rather than in their original order. This is a feature I think is missing in ChessBase (maybe it’s present but too deeply buried or obscure for me to find).
That is rather a lot of detail. As I worked on this stuff I realised there is a simple way to think about all of this work. Basically I’ve been doing CRUD programming. This is a disdainful term programmers use to describe standard business programming which so often comes down to Creating, Reading, Updating and Deleting records within databases. I knew CRUD programming was typically more time consuming and annoying than you might expect it to be, but didn’t recognise that I faced a CRUD task until I was half way through it !
Let me give you a tangible example of some of the difficulties I have been wrestling with. I have mentioned in a previous post that at any time the user can summon the game list for the current file (i.e. you can look at the list of games at any time, not just when you first open the file). I also allow the user to look at a couple of other game lists as well. The other lists are the “session” and the “clipboard”. The “session” is just a list of the games you’ve been working with since you started the program. The “clipboard” is, well it’s the clipboard. I think it is cool to let the user look at the clipboard.
Consider the following scenario. The user opens a big .pgn file, cuts most of the games to the clipboard, saves the (now much smaller) file. The user opens a second big .pgn file, selects most of the games, adds them to the clipboard, deletes them, saves the (now much smaller) file. Now the user looks at the list of games in the clipboard. The clipboard shows a huge list of games, nearly all the games from both the big .pgn files, and in fact those big .pgn files are now both small .pgn files. If the user picks one of the games from the clipboard to load and work with, where does it come from ? I really don’t want to keep all the games in memory, that’s not very scalable. On the other hand the file the game is coming from has been modified, and in particular the game has been deleted from that file.
This gave me quite a headache. I will outline in broad terms how my solution works. The conventional approach to saving a modified .pgn file would be to open the original .pgn file for reading, and then create a temporary working file to write to. Then everything we are keeping is written to the temporary file, and if and only if all goes well, we delete the original and rename the temporary to the original’s name. I modify this approach. Instead of deleting the original I rename it to (another) temporary file name. I keep this temporary file for the whole session. The clipboard games in our troubling scenario can be readily located in one of these temporary files. Simple and effective but it didn’t occur to me until all alternatives had been considered and rejected as too complicated and impractical. As Homer Simpson might say Doh!
Well I could write more about some of the other minutiae I’ve been looking at, but I’ll save us the bother by calling time on this for now. Talk again soon!