Pages

Monday, May 20, 2019

Learning to code

My brother recently suggested that we work on developing a helper app for a board game that we both play, as it'd be useful and, more importantly, give us a good excuse to do something together. (As parents of large families with young kids, it can be pretty difficult finding time to actually do this!) There was just one little problem with his suggestion—he's a software engineer; I am most definitely not. The only computer related class I took in college was a freshman intro to computers class, which was about as exciting as it sounds.

Ok, that's a little misleading. I've been messing around with computers since I was a little kid (including dabbling with several incarnations of BASIC), and have done a few of those online interactive language introductions (such as JavaScript). In college I worked for a small company where, among other things, I was their "computer guy" by virtue of knowing more about computers than anyone else, so I was responsible for networking, installation, and general troubleshooting.

Anyway, my brother wants to write this new app in C#, so I figured that if I'm to be of any actual assistance, I'd better learn the language! I ran through the relevant interactive intro courses on Codecademy and SoloLearn, which is roughly equivalent to reading the rules of chess but not actually playing a game.

We hadn't yet found time to get together and work on the project, so I considered what to do next in order to keep learning. A couple of years ago, after doing the JavaScript intro, I had started working on a console version of FreeCell, as it seemed like an appropriate learning challenge: clear, but uncomplicated rules, but also non-trivial to implement (at least for someone of my experience). I hadn't ever finished that project, so I thought it would be nice to do it in C#.

Shortly after I started working on that, my wife and I had a new baby! After coming home from the hospital, I started getting up at 3am to take care of him, so my wife could get some uninterrupted sleep, and I needed something to keep my mind off, well, sleeping. Working on this C# program was a great project for these early morning hours, and I made a lot of progress!

We'll call that phase 1 of learning to program in C#. Here are a few of the key things I learned (in no particular order):

  1. When I was "learning" JavaScript, I was just using an online code editor, which had some built in formatting features and error detection, but nothing like Intellisense in Visual Studio, which I've been using for C#. A feature like Intellisense is pretty amazing.
  2. It's amazing for several reasons: one, it helps reduce the drudgery of repeatedly typing the same sorts of things over and over again. (I'm not talking about code re-use here, but basic things like names) Two, it helps reveal to the novice (me) the internal logic of the language by showing me the sorts of things the compiler is looking for. Three, by reminding me of the arguments required by different methods. There is value in making errors, in that they are an opportunity for learning (and learning more concretely), but too many errors just leads to frustration and negatively impacts learning. Intellisense doesn't do the programming for me, as I still have to choose the correct options and use them correctly once I have them on the page.
  3. I was at first frustrated by the fact that C# is much more strongly typed than JavaScript, as it made certain trivial things more difficult. However, at a certain point in writing my JavaScript program, I had started to encounter unexpected behavior which took a long time to figure out, and some of it was due to implicit type conversion happening "under the hood". C# has been making me work harder to get things set up, but this has had the very important effect of making me think more carefully about what my variables and objects are doing! Rather than just stabbing at particular outcomes, I am thinking more about how the computer "thinks" about things.
  4. Oh dear, there is a lot more to learn! Continuing with the chess analogy I used earlier, I now know the basic rules, and have learned the basic principles of development (a term applicable to both chess and software!), but I am almost completely ignorant of combinations or structure.
Working on my C# console version of FreeCell (which is now basically complete), I had to repeatedly consult reference materials in order to figure out good solutions to individual challenges. The process of trying to solve those was very educational--much better than doing pre-built exercises!

I may revisit the FreeCell project in order to explore user interface development (a text-based card game is pretty clunky), but for now I'm moving on. My next personal project will be re-writing a a spreadsheet "app" I made many years ago, which I called "Improv Randomizer", which takes a variety of categories of musical forms and features, and within each category generates a random option to be used as a creative constraint in improvisation exercises. Unlike FreeCell, I am not aware of any actual apps that do this, so there is a (slight) real-world purpose to this project! The logic of the program is fairly simple (randomly access list elements), so the main learning challenge will be developing the UI. Even a simple Windows UI would be an improvement over my current spreadsheet version (although I could probably improve the spreadsheet version too).


No comments: