Computers: A Saga
When there's silence in my house ( a rare thing, you should know ), I like to think about giving Ben ways to focus his crazy intelligence on things that are not the TV. Some kids can watch TV and play, taking breaks from whatever they're doing to stare up at the TV a while; Ben can't stop himself. If the TV is on, there is nothing that will distract him from it, even if it's a dull documentary describing dental diagnoses of dingoes. His jaw slacks, his eyes glaze: it's as if he's watching The Most Fascinating Thing Ever.
As a more-interactive substitute for Neanderthalish TV-comas, we tried having Ben share Becky's computer. Being a Mac, there were a bunch of things you could get for it, and we figured it would be good for him to learn how to take care of a computer. This was the worst possible idea we ever could have had, and resulted in the following damages:
- Several of Becky's writings being lost due to Flash-game related freezes
- Mental anguish from listening to crappy sound effects ad nauseum
- Nagging, whining, and complaining when computer time was over
- And, the last straw: A glass of water spilled on the fancy Mac keyboard, shorting it out and turning it into a $75 toy for Alex to bang on
But we're not bitter; we just turned it off. His account, that is. Locked. No more.
"...but Daver! How will he learn about computers???" people ask me. As I've discovered, he will learn about computers the same way I did: by messing with them. And he'll learn faster and be able to do more at the same age as I was, regardless of whether he gets time to play Carmen Sandiego or not.
My father-in-law, however, who is the guy I call when I have the urge to go to Fry's and look at nerd toys, was still aghast that his grandson was not getting computer time at home. Since he always has to keep his gaming computer up to date, he replaced an old laptop with a new rig, and decided to donate his used laptop to the cause. So, since I can't handle there being a computer in my home which is not being used for something, (clever man, my father-in-law), I installed Carmen Sandiego and Python on there for him to play with, along with an e-book called Snake Wrangling For Kids. He's currently working through the book now, learning to program in Python.
I figure in about 6 months, he'll have built Skynet. God help us all.
Everything I Ever Needed To Know I Learned From Watching Kung Fu
...except functional programming. That I learned in college.
My professor at the time was a young dude who had the idea that the best way to learn about programming language design & construction was by learning five languages in one semester. Some were simple to wrap our C++-and-Java-bred minds around, like C, and some were painful to paradigm-shift into, like Prolog. But the first language, and the one that truly gave me insight into what makes a programming language a useful tool, was Scheme.
Scheme, the simple dialect of Lisp, the parenthesis-heavy language with terms like "car" and "cdr". Where tail-recursion is the paradigm of choice and the iterative, C-style "do-this-then-that" habits had to be broken before we could truly begin to program elegantly. I spent hours and hours writing tic-tac-toe in Scheme; I think the most important thing I learned was to avoid assuming that a particular convention works well in all environments.
To give you an idea, here's a lovely Fibonacci sequence generator in Scheme: (for the non-CS/math grads, the Fibonacci sequence is a pattern of numbers: 0 1 1 2 3 5 8 13 21 34 ... or, each number equals the sum of the two previous numbers ... which makes for a great little sample program )
(define fib (lambda (n) (cond ((= n 0) 0) ((= n 1) 1) (else (+ (fib (- n 1)) (fib (- n 2)))))))
Lately, as a mental exercise (read: to procrastinate on some of the less-interesting paperwork I was supposed to be doing ), I started to play around with Haskell. I'm having a ball, mostly because Haskell is so much more strict about eliminating side effects, which means that the language directly supports designs which are compositions of pure functions. Why does that matter? Well, if you can't mess around with memory or resources outside of your function, then you can't break things outside of your function either
.
Fibonacci in Haskell:
fib x = if x == 0 then 0 else if x == 1 then 1 else fib (x -1) + fib (x-2)
Why do I like this better? Well, aside from the fact that there's no stack notation ( operator, operand, operand...), so I can let my brain think in a more human way, it does away with all those blasted parens.
Of course, since this is about hour two with Haskell, I can't quite comment on whether I like it as a whole, but I can certainly see how programs developed with it are more easily proven correct; an entire class of possible problems is eliminated by eliminating side effects.
Anyhow, if anyone else is interested in learning Haskell too, and wants to put some code together on a side project ( purely for the fun of it ), let me know.