The reason is likely not what one would naturally think, the code isn’t too opaque, and the syntax wasn’t much of a problem for her. It was just so much work to get output. With my son, we worked on a really simple Python program working on his hand-me-down OLPC, my daughter was upgraded to an Acer Aspire 1 for her birthday.
I have been asked by many about using “kid friendly” programming languages. I think the people working on those are doing good work, however there is nothing “kid unfriendly” about the languages that I use for programming as an adult. I think that in general when educating our kids, we need to stop coddling them so much. Creating an approximation of an already dumbed down environment to write software to drive machines will not help them. Most of the kids that I have seen are already beyond logo and they don’t even know it. What they seem to want to do are real world things, and there is no reason they can’t.
What I settled on was to use Ruby for the tasks. It is a language that has a great REPL, and is easier to read. It also has the benefit of having a sane shell input mechanism as well as not requiring a ton of objects to get started.
We discussed what she wanted to do, there were several things, all of them were deeply social, but the one we settled on, I thought was the easiest to implement. I thought that encrypting messages to her friend where only she and her friend had the crypt key would be enlightening.
She agreed, so we started into coding it up. First we ended up working through a few encryption techniques on paper, taking short messages, converting them into their character codes and then shifting them by adding the char codes of each letter of the crypt key to each letter of the message.
def encode msg,key coded_msg = "" msg.each_char do |letter| coded_msg = coded_msg + add_cipher(key,letter) end return coded_msg end def add_cipher cipher,letter code = "" cipher.each_char do |cl| code = code + pad(cl + letter) end return code end def pad num length=num.to_s.length if length > 3 then num.to_s else padded_id='0' * (3-length) + num.to_s end return padded_id end
At first, she put the crypt key into the program, but we discussed that it would be a bad idea since anyone with the source code could then crack the message. She then asked me how her friend would decode the message. I told her that the only way was for her to create a “pre-shared key,” something that she told her friend verbally that they would both have to remember, only then could that key be used to decrypt the messages.
What we did was to create a multi step command line program to accept the key and then the message. We haven’t gotten around to the demux yet, but here is the mux:
print "Enter the crypto key, or die!: " key = $stdin.gets.chomp print "Tell me what to do ( 1 for encode, 2 for decode ): " op = $stdin.gets.chomp if(op.to_i == 1) print "Enter message to encode: " message = $stdin.gets.chomp coded_message = encode(message, key) print "Here is your message: \n" print coded_message else end
The nice thing about all of this is that the code is approachable, and the execution path makes sense… this happens, then this happens, etc… she can easily understand the flow of this program. We had significant problems with the flow of a client web application.
One of the first things that my daughter noticed was that whenever you make the crypt key longer, the message gets a bit longer, and that the encrypted message was many times longer than the original. So it is working, not only is she understanding programming, but basic cryptography as well. The only thing I am concerned about now is what happens when she is encrypting her posts on the social media site du jour at 16 with quantum encryption techniques. How will I ever crack her codes?