As those of you who know me personally will know that I am, quite vocally, not someone who enjoys programming. My main problem is that I write code so infrequently that whenever I sit down I've forgotten either the syntax of language or the parameters of the API, and find more time is taken with reading the docs or finding suitable examples than actually writing or thinking.
I visited my parents yesterday to help my 16 year old brother study for a test, and he also asked for some help with a programming assignment. Due either to a recent loss of computing equipment, or general difficulty in deciding on a language for teaching programming, they're using QBasic. Last time I used QBasic, I hadn't gone through a university degree and learnt half a dozen programming languages, so I found it all a bit easier this time. The problem was that I had no idea if half of the things I wanted to do had syntax in QB: you can't specify an array using numbers[4] = {1, 3, 6, 8}, so an example on the web (the only time I had to go outside of the help) pointed out that you use READ and a DATA statement. I remember seeing DATA statements in Commodore 64 code printouts in magazines, and not having any idea how the stuff quite how they worked. Surely it's easier to specify your data inline, rather than in a DATA statement? Isn't BASIC supposed to be, well, basic?
Anyway, below the fold is what I wrote. The goal was to teach my brother, and his brief was "write a roulette game". I insisted there would be no GOTOs, and no functions/subroutines, as he hadn't covered them at school. Generally the code had to make sense so he could read it and figure out how it all worked.
We finished it, and then, like the bastard I am, I deleted the bit that tests for odd and even and made him rewrite that. I suspect he'll find this post before actually rewriting it himself. Maybe not enjoying programming runs in the family.
(more…)