Sunday, June 16, 2019

Should everybody learn to code?

I saw something on SlashDot that raised the question: should all school children learn to code?

Yes.

For the same reason all school children should spend some time learning to sing, learning to do long division, learning to paint, learning some physics, learning some literature, learning to use a wrench and screwdriver, learning some history, learning some chemistry, etc, etc, etc. I believe that children who get a reasonably well-rounded, reasonable quality education grow up to be happier than those who don't, all else being equal. I don't have thousands of pages of peer-reviewed scientific research to support my belief, but I still believe it.

This does not mean that we should try to teach all children to be *good* programmers, any more than we should try to teach all children to be professional-level singers. We just need to introduce a wide-range of subjects so that they have a basic understanding of what the subject is about. After that, let their natural talents and interest drive where they go in-depth.

I never knew that software was my calling until I had my first opportunity to try coding in ... was it 1975? This introduction was *not* taught in school. It was a group called "explorer scouts", which may or may not have been associated with Boy Scouts of America, I don't remember. All I can tell you is that there were no uniforms, no camping, none of the trappings of Boy Scouts. The only activity I can remember was the programming. It was Fortran on a time-sharing system with a teletype. The fire it ignited in my brain overwhelms any other memories of the Explorer Scouts.  THIS is what I wanted to do; my path in life was obvious.


HOW TO TEACH IT?

So, how should programming be taught?  I don't know. I know there has been a lot of research and development in the area of programming systems for young people. Drag-and-drop icons representing programming constructs. I've glanced at them, and even used one briefly (it was a google doodle). It's OK, I guess.  I think an important goal is to give a child early success and a feeling of accomplishment. I don't think those systems actually teach *programming*, but I think they probably do teach some fundamental concepts that are needed for programming.

My concern is that those systems don't really give a flavor of what programing is like. If you sing in music class, you get a sense of what singing is. If you play touch football, you get a sense of what that is. I actually consider myself fortunate that I wasn't introduced to programming that way. I suspect I would have thought that it was kind of neat, but I'm not sure it would have lit the fire. Part of what inspired me with my exposure was just the limitless possibilities. I'm not sure you get that with drag-and-drop programming.

The problem with most languages is the sheer amount of infrastructure you need to master before you can do things.  To write a simple Java program, you need to define a namespace and a class.  To print something, you need to enter System.out.println("something");. To read a line from the user will require several lines of junk that would require hours of explanation if you want the person to understand what the lines mean. Granted, you could just boilerplate it and tell the student to ignore all that stuff till later, but I think that reduces engagement. As does the edit/compile/run cycle. I don't think Java is a good first language, at least not for young children (and maybe nobody).

I have taught a few people to program. Want to know what worked for me?

"NO!  DON'T SAY IT!  PLEASE FOR THE LOVE OF ALL THAT IS DECENT, NO!"

Basic.

"GAAAAAAAAAAAAAAH %@!&*$!!!"


BASIC???

Yep. And I mean BASIC Basic. Line numbers. One or two character variable names. No "else".

10 print "hello"
20 goto 10
run

I find that humor is a good teaching tool.  If your first program is an infinite print loop, it's kind of funny. Not very funny, but a little. Also, you definitely need a REPL (Read-Eval-Print Loop), which Basic is. No edit/compile/run cycle please.

It takes me an afternoon to teach somebody to program. We don't get sophisticated, but by the end of the afternoon we do end up writing a simple "text adventure" style game.

You are facing two doors.  Do you want the right one or the left one?
? right
A lion has just eaten you!!!
Try again?
? yes
You are facing two doors.  Do you want the right one or the left one?
? left
You found a gold coin!
Do you want to keep going?  Or turn around?  (answer "going" or "turn")
? turn
You are facing two doors.  Do you want the right one or the left one?

etc. See? More humor. How many ways can you kill the player?  :-)

I feel that the Basic language didn't get in the way of seeing the simple algorithm. Any other language would have obscured the simple beauty of what we were doing.

[Update] Now mind you, this is a one-day exercise! For somebody with more interest, I would have a second lesson with subroutines and gross Basic-style input parameters (globals, actually), and for the third lesson, we would switch to a modern language. Maybe Python? Maybe Java? Maybe Lisp? It would depend on who it is and what they might do with it.

Anyway, I did this 1-day lesson with my daughter (she was ... I don't remember ... maybe 10?) and she did well.  Afterwards, she did ask me some questions and got a little help.  Later that year she gave me a birthday present. It was a CD ROM with her updated adventure program. It has maybe a dozen "rooms" and lots of jokes and little surprises in it.  She was VERY proud of herself. (And me of her; I still have the disk.)

But she pretty much lost interest. I am confident it was *not* because of the primitive language. It was just because it didn't light a fire in her. Which is fine.

Anyway, I really think an afternoon of Basic is a good way to introduce programming to a newbie of any age.  I *know* it works.

4 comments:

John Jacobsen said...

I learned on BASIC in the early '80s. It didn't do me any harm, though I had some unlearning to do soon after (unlearning that was at least as fun as the learning).

I'm still teaching Clojure at work after five years of doing so. One thing that I'm noticing is that experienced developers sometimes have a harder time learning Clojure than beginners. I actually think some Lisps, including (or especially?) Clojure are easier for newcomers who have fewer deeply ingrained mental models to shed. (I programmed for decades in several languages and had a somewhat difficult time learning Clojure, especially the more functional aspects.) One big benefit of Lisps is that the syntax fundamentals can be taught in five minutes. I guess the same is true of BASIC.

I guess I'd offer any Lisp for consideration as an alternative to BASIC, partly because you can build real things in Lisp (and get paid real money).

Steve Ford said...

Doh! I forgot all about Lisp! Thanks for the reminder!

One thing that is very good for programmers is to stretch their brains; make them think in very different ways. Having an afternoon introduction to programming with Basic, followed by another afternoon with Lisp ... I think I like it. And even though Lisp allows non-functional techniques to be used (e.g. data is mutable), teach it as pure functional. I suspect Clojure is a good choice, although for a youngster's second day of programming, I probably would not wade into higher-order functions -- remember, I'm trying to give a flavor for programming; this is before interest or talent has surfaced -- but I really like the idea of stretching the brain to encompass two very different approaches, before either one has imprinted too deeply.

I haven't thought much beyond day 3. I.e. I'm not trying to put together a curriculum. Just a "I bet I can teach you to program in three hours"

Anonymous said...

I was asking myself same question - some kind modern Basic or ... Python, Java?

Was advised to look at this one - https://en.wikipedia.org/wiki/Processing_(programming_language)

mike said...

code.org is a great start. even if it is drag and drop code blocks, the kids learn really fast "if I do this, then this happens." Super valuable.

I did read a tweet yesterday that said (paraphrasing), "are you teaching your kid to code for them or for you?" I thought that was an interesting take.

I personally am teaching/showing my daughter python. I showed her some basics when she was 7 or 8. She is 9 now and was asking to learn more.

I very much agree about introducing code much like music or sports. It can introduce a certain way to think about things and for them to gain some level of familiarity with code, that will be valuable.

We have also used Osmo coding, Kano hardware with coding interface, and Swift Playground iPad app.