Monday, September 30, 2013

Lesson 24 - Accidental Arithmetics

Tonight she wanted to have a lesson just before bedtime. It's usually a bad idea, but I came around because she was so eager and didn't seem too tired.

The plan was to complete the Turtle Roy drawing from the last time, until an accident happened.

We started with turtle graphics and this time, I think, was the first time she remembered without any help that you use "fd 100" to move forward 100 pixels. She also mastered the clock trick from last time to determine whether we should turn right or left.

Then she accidentally typed just


and the computer answered


Then teased her to try if the computer can do 1 + 1. And then we had a lot of fun doing arithmetics. She was really excited, for example, what 77 + 77 is.

Sunday, September 29, 2013

Lesson 23 - Clock

Today we did a lot of drawing with Turtle Roy. The key thing that was learnt was that turning right is turning clockwise and vice versa. The directions left and right were pretty well learnt already but when the turtle is facing downwards, it's not trivial to say whether you should turn left or right to get to the direction you want to go. (not even for me)

So we placed a pen on the computer screen and turned it to the direction we wanted to go. Then, if it appeared to be the direction the clock always turns, it's Right.

What we actually tried to draw with Turtle Roy this time is her name. We go this far. We'll continue with that on the next lesson. It's amazing that she doesn't really care whether we should write from left to right or the other way. She chose to write the arabic way because there was "more room to the left".

She also knew exactly when we should lift the pen up and when to put it down. You have to lift the pen up to move it without drawing on the screen, you know.

This lesson was a fun and rewarding one, thanks to not having it just before bedtime. She remembered the space between the function name and the argument very well. That's because I've given her a cookie every time she remembers it. 

Bribery works. We've run out of cookies now, but we don't need them anymore either.

Thursday, September 26, 2013

Lesson 22 - Reverse

This time we started too late. She was too tired to learn. We should never do this just before bedtime...

Anyway, it was Haskell time. The idea was to teach the computer who the girls are and then turn them upside down.

So we opened ghci and started teaching. Like last time with Turtle Roy, we used let to define a new thing. I suggested the word "tytöt" (girls) but we chose to use the name "t" because it's shorter and the computer doesn't really care. So,

    > let t = ["mila", "elena"]

Then we discussed head and tail a bit and tried them

    > head t
    > tail t

I took a while to make a distinction between a character string and a list and that tail returns a list of strings in this case. I'm quite sure she ignored my talk. But let's see. Maybe she's a natural with types.

Next we tried reverse:

    > reverse t
    ["elena", "mila"]

And finally the funniest thing. I introduced a new function map which takes a list and another function (POW!) and performs the other function for all things on the list. So we applied reverse to all the girls:

    > map reverse t
    ["alim", "anele"]

That was fun. Then we reversed daddy too.

Tuesday, September 24, 2013

Lesson 21 - Characters

Last time we talked about getting to know all the characters that one can type using the keyboard. Today she wanted to get on with that, so we skipped the turtles and went for vim.

She typed vim merkit by herself. In vim she instantly knew she has to press i to start writing text. Then she wrote something like

    numerot 1234567890©@£$...

and so on. We went through the numbers, then numbers with the shift key, then with alt and finally with both shift and alt pressed. We discovered a host of fun characters that I had no idea were hidden behind the number keys.

Then the same excercise for all the letter keys. There was a lot of discovery and she managed to save the document after each line of text to make sure we won't lose our work if the battery goes out. That's an important lesson for you too :)

So, even though we hadn't used vim for a week, she mastered it. She also remembered that cat is used to print file contents and, with some assistance, that we can pipe it to say to have the computer speak.

All in all, I noticed she had improved writing skills and general confidence in her own abilities. And it seems that my fears about her forgetting all the learnt skills in a day were without foundation. Even though it sometimes feels that nothing seems to "stick", a lot does indeed.

Saturday, September 21, 2013

Lesson 20 - Spider

After yesterday's repetitive practise on Turle Roy basic movements, we were quite well prepared for today's lesson. We started teaching the computer immediately and wrote (again)

    let askel = s [fd 100, lt 90]


    let neliö = r 4 askel

Then (the excitement thickens) we ran our neliö function and had the turtle draw a perfect square. And again. And again.

Then we set to implementing the "spiderweb" thing that I showed her earlierly. The idea is to draw a square, then turn right, say, 5 degrees, then rinse and repeat. So first we taught the computer to do the "square and then turn" thing, the naming of which was left to her. She chose to name it xz. And then we wrote

    let xz = s [neliö, lt 1]

She chose the 1-degree turn against my advice. And finally

    let spider = r 360 xz

And we got a very fancy picture. Not the spiderweb thing though, because of the 1-degree turn, but a cool thing anyway. Then we modified the program a bit to draw the actual spiderweb. We saved our work, so that you can try it out yourself.

This was a fun lesson! She would have wanted to do some keyboard practise in vim too, but we ran out of time.

Lesson 19 - Left & Right

Yesterday she announced that she wants to learn to code. So we went back to Turtle Roy to do some programming.

We started, once again, with some basic turtle graphics stuff like

    fd 100
    lt 90
    fd 100

.. and so on. I was a overly optimistic to presume she'd be able to memorize how to turn to left and right and how to move forward in a blink of the eye. In fact, it proved quite hard this time. Maybe the problem is that left and right themselves are quite tough concepts for a 4-year old. When you add that we discuss in Finnish and code in English, and that English is not written the same way it's pronounced, I can understand that it's not easy. 

So this time we spent most of our time learning turtle graphics and trying to memorize left and right. On the other hand she easily remembered how to construct lists using square brackets around them and commas between the list elements...

All in all, this lesson felt like a step backwards. Or maybe more like a reminder of the fact that she's just 4. So let's take it easy and have fun.

It is said that Logo and turtle graphics are a great way for kids to learn programming. However, I realised yesterday that teaching is usually started at age 12 or 13. Finnish children of that age can

  • speak / read / write English
  • understand numbers up to 1000 (?)
  • understand some geometry, including angles
Children at four, on the other hand, can do none of these things. So the learning curve is in fact quite steep. 

But we won't give up! 

I'm open to new ideas too. What should we do instead, or in addition to Turtle Roy?

Tuesday, September 17, 2013

Lesson 18 - IO Monad

I'm slipping. I forgot to post yesterday even though we had a lesson.

Yesterday we visited Haskell for the first time.

That was just because the "say" function in Turtle Roy didn't produce any speech though. Fortunately I had setup her GHCI so that it includes my special helper module Napero which provides easy single-letter shorthands to some common functions. For those not in the know, the Roy language used in Turtle Roy is syntactically very similar to Haskell, so we can switch between the two without struggling with different syntaxes.

The main thing of lesson 18 was the idea that you can define a list of actions and then sequence them into a single action that performs all of the actions on the list. So, in Haskell we did

    s [say "mila", say "ella"]

Where s is a shorthand for sequence and say is a wrapper for the command-line say command. Composition is a powerful tool! This is coding!

Next we started "teaching the computer". The idea was to teach the Turtle Roy to draw a rectangle, which consists of four equal parts. Each of the 4 parts proceeds 100 pixels and then turns right. We called this operation "askel" and taught the computer to do "askel" like this

    let askel = s [fd 100, rt 90]

When we had taught the computer, i.e. defined a function, we called askel 4 times and voilá, got the rectangle together!

Then we concluded that "askel" is almost like "haskell".

Next up: define the rectangle function.

The list syntax is something we'll be revisiting time after time until it feels natural to her.

Sunday, September 15, 2013

Lesson 17 - Song Finished

Today we completed the "head shoulders knees and toes" song by adding a new line "eyes and ears and mouth and nose" and yank-pasting a couple of lines to the end. It took about 15 minutes most of it we spent typing the 5-word line.

She remembered the space between words. She had more confidence with the letters G and B which we practiced quite a bit when moving around the document.

Next up: programming. I'be prepared a bunch of Haskell helpers already. Not sure whether to start Haskell next time or stick with Turtle Roy...

She taught Mom some more vim after our lesson. Mom proved to have mad unix skillz.

Thursday, September 12, 2013

Lesson 16 - Mom Learns Vim

This time we practised vim movements quite a bit

  • 0/$ - start/end of line
  • 1G - first line
  • G - last line
  • 2G -second line
  • w - forward one word
  • b - back one word
  • j/k - down/up
And that's quite enough for most of your movement needs. We'll practice those more later.

Then we did some editing, using dw to "delete word" and then i to insert new text. She remembered to exit insert mode, of course.

Then we yanked a line with yy and pasted with p. Those she remembered too. And deleted one line with dd, so that our little song goes now like

  head shoulders knees and toes
  knees and toes

  head shoulders knees and toes
  knees and toes

Then we made the computer speak this out load again with cat pää|say. She taught her mother how to do that.

Then she insisted on teach mom some vim too. And so also mom is capable of entering and exiting vim! She'll get another lesson tomorrow.

Tuesday, September 10, 2013

Lesson 15 - Gravity

Today we implemented the GOF Patterns starting from Singleton and Visitor.


We practised the most popular method of code re-use: copy-paste. In vim it's called yank-paste. First we added a new line to our song. It was easy. Now the song goes as in

  head toes and knees and toes
  knees and toes

Then I teached her how to move up and down in vim, using the j and k keys. We had an exercise where I shouted UP and DOWN randomly and she had to follow the orders with the cursor. First she tried to use the mouse but we soon established that vim doesn't obey the mouse. Soon she mastered the movevents and we were ready for copy-pasting. So, we moved to line 1 and yanked it using "yy". Then went to the end and pasted it using "p". This for both lines. She was happy to achieve so much with so little effort!

Then she told me the lyrics are all wrong. They should go like "head shoulders knees and toes" instead. Damn! We decided to fix that next time and had fun with "cat pää|say" instead. The computer was a lousy singer but we listened to it many times nevertheless. This was a fun lesson!

After the lesson I questioned her and she still remembered the movements, yanking and pasting. The hardest thing is still remembering to enter a space between words. In fact, I promised her a cookie for each space she remembers and she actually remembered on this time. The offer still stands, so let's see if she remembers better next time.

Oh, and yesterday we discussed whether people on the other side of Earth stand head-down. We discussed gravity and she drew a very nice diagram that show the force vectors for two girls on the opposite sides of the world:

Friday, September 6, 2013

Lesson 14 - Back And Forth

We started by moving the "pää" file back to the home directory. It took some time to establish that the snake-like tilde character represents the home directory and she decided to call it the "waves of the ocean" character. I think it's good to have a memorable name for that.

Then it was vim time. She knew that to edit the file, she has to use vim, and to open the file in vim she has to type "vim pää". She also types it correctly, even including the space between the words.

In vim, we practiced movements. Use 0/$ to go to the beginning/end of the line. Then we used w to go to the end of the current/next word. We moved around quite a bit, then appended the missing "the" word in the file that will eventually contain the lyrics of the "head toes knees and toes" song. She didn't remember the a/append command, but we memorized that append is a lot like "Abhem", who is one of her friends. Maybe remember next time?

We enjoyed the power of vim by repeating the previous command with "." and even tried "10." to repeat it ten times. Then u for undo. At last we had the first line of the lyrics ready!

And that was enough for here this time. Too tired to go on. Better quit while winning, right?

Tuesday, September 3, 2013

Lesson 13 - Desktop

The main challenge this time was to keep the smaller girl entertained while practising mad skills with the other. Fortunately there was a certain "makkarapeli", i.e. a monster-feeding game on the iPad...

She remembered the file name from the last time and that we can use vim to edit it. She also typed both correctly. The challenge is still to remember to type a space between the program and the file name. Anyway, we added a new word to our pää file and had the computer recite the file again. All this went quite smoothly and quickly this time.

Then we discussed directories for a while and moved the pää file to a directory called "Desktop". She remembered the word move from the last time and that the program is actualy spelled mv. It was fun to discover that the pää file could now be found on the computer's desktop. We even opened the file in Textedit, but she was not very enthusiastic about doing any editing to the file this time. So we decided that it was enough.

But it wasn't. With some help, she googled for pictures of pricesses, then saved a photo of a cake on the Desktop. We used "ls Desktop" to list the files on the desktop on the command-line. Then discussed the hard disc and directories again.

Then to Turtle Roy, where she demanded that we must make a circle this time. While I was making oatmeal and pampering the hysterically crying smaller girl, my vim-girl learned how to type square brackets and managed to produce the following program (I practically dictated this one):

    s [lt 10, fd 10]

Here s is a function that runs the listed actions sequentially, i.e. turns left 10 degrees and then proceeds 10 pixels. Then she repeated this a few times and declared that she can see the angles in the output, hence it won't form a circle. So I taught her how to edit the command line so that it will proceed just 1 pixel and turn 1 degree. Then she repeated that one for some time and was convinced that a circle would appear in the long run. 

The little one was now playing makkarapeli and not yelling or bashing at us or the computer, so we were now able to discuss programming a bit. The thing was that repeating the steps manually would be tiresome and we should use a function repeat to repeat the step 360 times for a full circle. I demonstrated this and we were both happy with the result. Next time she'll do it herself.

Afterwards, while eating oatmeal, she proclaimed cheerfully:

    "I can code!"

Then with a smaller voice: "Not as well as daddy though". Practice makes perfect.

Monday, September 2, 2013

Lesson 12 - Head and Toes

This time we started with a new command mv that we used for renaming the file "ihmisentarvikkeet" to "pää". I think she had great insight when she explained to me why you cannot use tab-completion when typing the new file (the file doesn't exist yet so the computer cannot guess it).

We used ls to list all files and find the new one in the listing. Then we piped the output of ls to say to have the computer speak it out loud. I promised to install a better voice to the computer so that it would be better at Finnish. She made me promise that we install it together when I've figured out how to do it.

Then it was Vim time again. We learnt to navigate to the end of the line ($) and to the start of the line (0). Then we added another word to our song (with a=append), which now goes like

    head toes

Then we had the computer "sing" it with cat pää|say. Concentration was hard and the last command too like 5 minutes to get right. 

Keep calm. Baby steps. Practice makes perfect.