{"id":385,"date":"2016-06-01T07:00:26","date_gmt":"2016-06-01T14:00:26","guid":{"rendered":"http:\/\/eriknovales.com\/blog\/?p=385"},"modified":"2016-06-01T07:00:26","modified_gmt":"2016-06-01T14:00:26","slug":"ludum-linguarum-the-tools","status":"publish","type":"post","link":"https:\/\/eriknovales.com\/?p=385","title":{"rendered":"Ludum Linguarum: The Tools"},"content":{"rendered":"<p><em>(Ludum Linguarum is an open source project that I recently started, and whose creation I\u2019ve been documenting in a series of posts. Its purpose is to let you pull localized content from games, and make flash cards for learning another language. <a href=\"https:\/\/github.com\/enovales\/LudumLinguarum\">It can be found on GitHub<\/a>.)<\/em><\/p>\n<p>When I started working on Ludum Linguarum, I decided to use it as an opportunity to exercise what I had been learning about <a href=\"http:\/\/fsharp.org\/\">the F# language<\/a> on the side. This might seem like kind of a strange decision out of context, but there were a few reasons why I felt that this made sense:<\/p>\n<ul>\n<li>I already had a good bit of familiarity with the .NET stack, having spent a good chunk of my years in the gaming industry writing tools in C#. <\/li>\n<li>Because of the frequent use of C# in games and editors, I felt that there would be a greater likelihood of me finding useful, easy-to-integrate libraries and documentation for reverse engineering games than on other stacks. <\/li>\n<li>I write <a href=\"http:\/\/www.scala-lang.org\/\">Scala<\/a> at <a href=\"https:\/\/twitter.com\/\">my day job<\/a>, so I figured that I would be reasonably well-equipped to deal with the functional programming aspects of the language, even if I had never really touched <a href=\"https:\/\/en.wikipedia.org\/wiki\/OCaml\">Ocaml<\/a> before. <\/li>\n<\/ul>\n<p>At the very beginning of the project, I was working on learning F# on my commute, using <a href=\"http:\/\/www.mono-project.com\/\">Mono<\/a> and <a href=\"http:\/\/www.monodevelop.com\/\">MonoDevelop<\/a> on an old netbook that I threw Ubuntu on. This worked (in that it is totally possible and viable to write F# and .NET code on non-Windows platforms), but later on I got <a href=\"http:\/\/www.dell.com\/XPS13\">a proper new laptop<\/a>, threw Visual Studio 2015 on it, and never looked back. The added benefit of doing this, of course, was that, running under Windows, I could easily install and <em>run<\/em> the games that I was reverse engineering.<\/p>\n<h3>The benefits<\/h3>\n<p>All in all, I have been very pleased with my decision to use F#. Using a functional-first language let me construct composable, easily-testable pipelines, and I feel this really saved me a bunch of time as the project grew. The language is very similar in capabilities to Scala for application code, albeit with significantly different syntax and a slight verbosity tax.<\/p>\n<p>When I think back to similar code I\u2019ve written in the past, I feel that my F# code is more concise, easier to understand, and with less room for bugs to creep in, compared to C++ and C#. This applies both for simple parts of the code, as well as much more complex parts. In a future post, I\u2019ll go into this in some more detail.<\/p>\n<p>I would go so far as to say that the things that slowed me down the <em>most <\/em>were when I strayed furthest from the functional style, and just used the full console application and the full game data as my testbed. (The reason I did this is that it can be a bit of a pain to construct test data that is compact, concise, and doesn\u2019t include any actual copyrighted material.) As long as I wasn\u2019t too eager, moved at a reasonable pace, and built up a decent test corpus, things worked out well.<\/p>\n<h3>Project setup<\/h3>\n<p>Initially, I used the standard .fsproj and solution setup in VS. The project was set up as a plugin-based system, where all main build outputs were copied into a single output directory, and <a href=\"http:\/\/www.nunit.org\/\">NUnit<\/a> test projects were simply run in-place. This worked OK, but as I got closer to actually releasing the first version of the project, I decided that it would be better to migrate the project to the <a href=\"http:\/\/fsharp.github.io\/FAKE\/\">FAKE build system<\/a> and <a href=\"https:\/\/github.com\/fsprojects\/Paket\">Paket dependency manager<\/a>. (Using those makes it simpler to keep dependencies up-to-date, and hopefully easier for the curious or motivated to build and run the project.)<\/p>\n<p>I used the open source <a href=\"https:\/\/github.com\/fsprojects\/ProjectScaffold\">F# Project Scaffold<\/a>, and reconstructed my old project setup. It took a little bit of experimentation, but I was able to get up and running pretty quickly. I did run into an issue where the recently-released NUnit 3 isn\u2019t supported by FAKE, and I did have to do some legwork to get everything building with F# 4 and .NET framework 4.6.1, but it wasn\u2019t too bad. Now I have a very simple system to build, test, and package the project for release.<\/p>\n<p>The latter is <em>particularly<\/em> important \u2013 I don\u2019t have a lot of extra time to spend on overhead like manually making builds and uploading them, so it\u2019s much easier for me to change the way I work, and change my project to conform to some existing conventions. One example of this is that the console program used to have no project dependencies on its plugins \u2013 they were copied as a post-build step into a separate <strong>plugins<\/strong> directory in the build output. This was done out of a bit of a purist mindset (and was what I had done on some other projects in the past) \u2013 but when I migrated to FAKE, this presented some problems, as it was difficult to duplicate this exact behavior. The solution was to simply abandon purity, adjust the way that I did things, and just add project dependencies to the console application against the plugins. Realistically speaking, anyone developing a plugin is probably going to have the full source handy anyway, so why get hung up on this?<\/p>\n<h3>Other libraries<\/h3>\n<p>So far, I\u2019ve pulled in just a few other libraries. One is <a href=\"https:\/\/github.com\/praeclarum\/sqlite-net\">sqlite-net<\/a>, a SQLite wrapper, and another is <a href=\"https:\/\/github.com\/gsscoder\/commandline\">CommandLineParser<\/a>, to allow me to construct verb-driven command line handling in the console application. I spent a little while wrestling with both, but now I have a couple of wrappers and things generally set up in a way that works well. (I actually switched back and forth between the old version of CommandLineParser and the new beta one, and wound up sticking with the new beta as it fixed at least one annoying crash relating to help text rendering when using verbs.) I also wound up adding the venerable <a href=\"http:\/\/icsharpcode.github.io\/SharpZipLib\/\">SharpZipLib<\/a> library for zip archive support.<\/p>\n<h3>Summary<\/h3>\n<p>In summary, I\u2019m glad that I have a setup now, using FAKE and Paket via the F# project scaffold, which is good for rapid development in Visual Studio, has good testing support, and one-line release packaging and deployment. There were a few bumps along the way in arriving at this setup, but I can wholeheartedly recommend it to anyone working in this ecosystem.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(Ludum Linguarum is an open source project that I recently started, and whose creation I\u2019ve been documenting in a series of posts. Its purpose is to let you pull localized content from games, and make flash cards for learning another language. It can be found on GitHub.) When I started working on Ludum Linguarum, I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[7,9,10],"tags":[],"class_list":["post-385","post","type-post","status-publish","format-standard","hentry","category-development","category-games","category-ludum-linguarum"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/eriknovales.com\/index.php?rest_route=\/wp\/v2\/posts\/385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eriknovales.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eriknovales.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eriknovales.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eriknovales.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=385"}],"version-history":[{"count":0,"href":"https:\/\/eriknovales.com\/index.php?rest_route=\/wp\/v2\/posts\/385\/revisions"}],"wp:attachment":[{"href":"https:\/\/eriknovales.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eriknovales.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eriknovales.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}