It Boggles the mind

For several years I have wanted to learn one of the newer programming languages. There is still a use for COBOL programmers (read this interesting column which compares COBOL to Latin and explains why both languages are still important to understand), but that is mostly at companies with a huge investment in “legacy” systems. All the companies I have worked for since I became a programmer have replaced their older systems or are in the process of doing so.

There are a few difficulties in learning a new language, even if learning languages come easily (as it does for me). First, there’s the question of which language to learn. Java? C++? Visual Basic? Perl? I did learn some Python several years ago, but we only used it for some simple information-sharing on the company intranet. I tried to teach myself C++ from a book, but got stuck when the exercises dealt with card games instead of the business applications I am much more familiar with.

Then there is where and how to learn it, which includes how much to spend in the process. I learn best by doing – and I can’t see how you could learn a language (either a foreign language or programming language) except by using it. But that means having the software and a computer that can run it, plus an idea of what I want to make the software do. I’ve taken some free online classes (free to me, part of a service paid for by my company to provide continuing education for IT people), but they only taught facts about the languages, with no practical exercises.

A couple years ago I took an online course using Alice, which I blogged about here. It was fun, and helped me get a feel for object-oriented programming, but provided nothing I could use directly in another language. I downloaded something called Greenfoot, and Al and I found some simple but fun games written on that platform, but I didn’t get very far at all when I tried to write my own.

Last fall a team at work determined that we should use Infopath and C# to support our proposed redesign of the approval process that is at the center of my job. (Currently it is email-based, which works but has a number of drawbacks.) I had been trying to learn how to use workflow in Infopath using a book I had purchased, but it quickly became clear that the real work would be done in C#. So I started looking for resources for learning the language.

I found a free online tutorial, but it had no exercises for me to do. Reading examples of code is just not the same as having to write them. I kept looking, and found an excellent resource that I have been using for the past few weeks. Its lessons take me step-by-step through the basic syntax of the language, not assuming any prior knowledge of other languages. It includes practical exercises doing common tasks in business, such as placing an order and creating a sales receipt.

I was especially pleased to find out I could download Visual C# 2008 Express Edition for free from Microsoft. It’s easy to use, especially when it comes to debugging my code. The programming exercises in the lessons are actually segments of code already written, which you just type in using Visual C# Express. Even though I’m not coming up with it myself, by typing it I’m learning the syntax. Besides my own typing errors, there are occasional errors in the code listings in the lessons, and Visual C# Express helps me greatly by pinpointing syntax errors.

After about a dozen lessons, though, I got tired of copying someone else’s code. My husband had come up with a good suggestion for a programming project, last time we played Boggle. Personally I like playing games like Scrabble and Boggle the old-fashioned way rather than on a computer screen. (Freecell is different – I’ve done it with physical playing cards but it takes a lot of room.) But the idea of writing a Boggle program appealed to me. (OK, it’s not a business application. But what can be more interesting than a word game?)

I had no problem figuring out what kind of objects and methods I needed to create. It was just a matter of learning the C# syntax for dealing with arrays – since sixteen cubes with six sides per cube is best handled with an array of sixteen by six, rather than sixteen (or 96!) different objects. Before long I had defined my array and populated it with the letters (which my husband kindly wrote down for me from the letter cubes in our game).

But putting the cubes into the four-by-four grid was another matter. How do I determine if a cube is assigned to a place in the grid yet? Rather than come up with a “is-it-used-yet” property for the cube, as I had originally intended, I realized it was easier to work from the other direction, determining if a place in the grid was used yet by whether it had a letter value or only a blank. (Eventually I’d like to give this a graphical user interface, but so far the lessons have only covered console applications, which are character-based.)  I thought now I was all set – except that the code didn’t work. I got one letter and no more, and after that either the program ended, or I was stuck in an endless loop.

Learning a new language’s syntax is really only a small part of the programming challenge. My errors, once I finally located them (after well over an hour reviewing my code, inserting commands to display values of the variables as the program ran, and figuring out where they came from), were logic errors. When I only got one letter assigned, it was because I forgot to reinitialize a variable before running the loop again. When it got stuck in an endless loop, it was because I had not set the upper limit of the random-generator high enough and I was only filling three rows and three columns of the grid, leaving seven letter cubes with no place to go.

If you’re not a programmer, much of this may not make sense to you. But for me, the frustrations and satisfaction of programming are similar to other kinds of puzzles. I’m currently working on a jigsaw puzzle in the basement (I’ve discovered that it’s a surprisingly good activity to occupy my hands and eyes while I pray), and there is the quick satisfaction of putting most of the outer edges together, followed by frustration as I can’t find any particular color or pattern to work on, because the picture is a mosaic and the patterns and colors are repeated throughout. Then I find a few pieces that fit together, and then some more, and suddenly I have a central section to attach more pieces to.

I do crossword puzzles frequently, and sometimes I get a few words that interlock and then get completely stuck. I put it away, then take it out again later, and realize I misread one of the clues (for instance, “rn” looks like “m” to my 48-year-old eyes), and the answer to that clue gives me what I need to get several more words. Or maybe I wrote down a word that makes sense for the clue and fits in the blocks, but just isn’t the right word. When I finally try erasing it and go back to work on the words that cross it, suddenly everything makes sense.

I can now produce lots of 4 x 4 sets of letters based on the Boggle cubes.

R B C Q          I B E O          M U U N          D I D I
R T A S          H E R R          O A S I          G I A R
G U D E          T T P U          E I S N          L F E A
D Y U L          T Y R E          B E S I          N W T A

Now, of course, I have to start thinking about how to allow the user to type words into a list, and to check them against a master list of valid words and calculate the user’s score. Do I even consider having multiple players, and figure out how to cancel out words that appear on more than one list? Or have a computer player that comes up with words that the player(s) didn’t see?

I’m sure before I get much further, I’ll be as frustrated as I was earlier today before I spotted my errors. But then I’ll figure it out, and there’s a great sense of satisfaction in finally seeing a program work the way it’s supposed to. Besides, a Boggle game will give me something to do during lunch hour.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: