Using Xcode for Advent of Code 2017

This year I'm using Swift as much as I can for Advent of Code. After fiddling with a few different coding environments, I settled on Xcode. I have a "Command Line Tool" project that I reset everyday to contain some minimal boilerplate code. Starting with that, I code my solution for the day's AoC puzzle.

This might seem like the obvious choice — what else would one use for writing Swift code? — but I actually started out with CodeRunner, a great tool that I used last year as well. I switched to Xcode after a few days because I was having trouble getting Swift breakpoints to work in CodeRunner.

On top of that I realized how helpful the other goodies in Xcode are, even for one-off exercises like AoC. By using Xcode I get integration with the documentation, automatic "fix-its" for common syntax errors, and "Edit All in Scope". That last feature is handy because when I catch myself agonizing over a name I can stop, use anything quick that comes to mind, and move on. It'll be trivial to change the name when a better one comes to me, usually while I'm on some other part of the code. I don't need the full "Refactor" feature, which is a bit slower to use, because all my code is almost always in one file.

I do keep CodeRunner on my Dock and use it all the time to try out bits of syntax in various languages. It's much easier to open a new file and start coding, and possibly never even save the file, than to set up a full-blown project directory. I have used Swift, Python, Java, and Objective-C to code AoC solutions, all in CodeRunner, and usually the integration with the respective language's symbolic debugger worked fine.

You might think a Swift playground would be just the thing for AoC, but I have not found that to be the case. For one thing, as far as I can tell there is no support for symbolic debugging. For another thing, AoC puzzles sometimes involve loops with millions of iterations, and it is prohibitively slow to have the results pane updated on every iteration. As far as I know there is no way to turn that off.

Out of curiosity I took a quick look at AppCode and VSCode. Both are highly un-Mac-like and required more of an investment than I was willing to make at this time.

An approach I might try when I'm feeling my hacker oats is to do my Swift coding in Terminal, with vim in one window and lldb in another. The oats aren't quite there yet, though. Maybe next year.

Leave a Reply

Your email address will not be published. Required fields are marked *