DZone
Agile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Agile Zone > Kids Coding, Part 1

Kids Coding, Part 1

When you teach a kid to code... Take a look at this article that follows one developer attempting to teach his kids Haskell.

Michael Snoyman user avatar by
Michael Snoyman
CORE ·
Sep. 16, 18 · Agile Zone · Opinion
Like (3)
Save
Tweet
4.34K Views

Join the DZone community and get the full member experience.

Join For Free

I’ve been wanting to give my eldest child (Eliezer, now 10) a chance to learn to code for about a year now, with little success. My second child (Gavriella, now 8) is also ready to start learning some coding. “Ready” to me means “they have a decent enough grasp of written English.” (Yakov, my 6-year-old, also wants in, but unfortunately is going to have to wait a bit.)

I know how I learned to code: sitting at a DOS prompt since the age of 2 and reading a massive “Teach Yourself QBasic in 21 Days” book. For various reasons, this doesn’t seem to apply to the next generation. I’ve looked into other modern approaches, including the graphical programming environments. My kids enjoyed some of this, but this week told me that, “It’s fun, but we’re not learning anything.”

Previously, I tried teaching Eliezer some Haskell by writing up lessons for him. Whether because of my writing or his interest, it didn’t work at the time. I decided to not go down this path again, and an hour ago sat down with Eliezer and Gavriella for their first lesson. I’m winging this completely, but here’s the approach I’m taking:

  • Keep the computer in front of me and show them things
  • See what confuses them, what interests them, and follow that
  • Give them one or two exercises at the end to reinforce the ideas
  • Keep the lessons short to keep their interest
  • Write up a blog post right afterward to record what happened, so I can learn for the future. After all, Yakov and Lavi (the baby, aka #YoungestHaskeller) need to learn too

This is the first of these summary blog posts. Caveats:

  • This will likely be incomplete
  • The material is very much geared towards my kids and probably won’t generalize
  • I have no idea how long or frequently I’ll be doing this.

I considered making these private notes for myself instead, but thought some others may be interested, so I’m posting publicly.

Without further ado!

Python Portion

  • Previous experience with Haskell made Eliezer think it was too hard for him, so we decided to learn Python instead. He has some experience with that from Code Combat.
  • I started at the REPL and demonstrated printing strings. We made some typical jokes (yes, they were fart jokes) in text form, which made the kids giggle. Upshot: they learned about strings, and stayed interested.
  • I demonstrated that basic arithmetic works at the REPL.
  • I opened up a hello-world.py file and demonstrated how you could write the same stuff from the REPL in a file.

This was the point where Eliezer commented that it looked a lot like the Haskell he’d seen. I’m not sure what it was, but somehow it clicked with him that whatever scared him off of Haskell previously wasn’t a real issue. We decided together to switch over to learning Haskell instead, which I’m quite happy about (more because I know the language better than anything else).

Haskell Portion

  • Did the same print, string, and arithmetic stuff at the GHCi prompt and in a file.
  • Asked them what 2 + 3 + 4 was, they got that.
  • Asked them what 2 * 3 + 4 was, they got that, too.
  • Then 2 + 3 * 4, and I was surprised to find out that they knew about the order of operations already. Yay, school system!
  • They mentioned parentheses, and I told them that would be the same way to do things in programming, and showed them (2 + 3) * 4.
  • Next, we talked about print 2 + 3. They had some inkling that this wouldn’t work, but couldn’t be sure of why.
  • I then branched into the next topics…

Types

  • Types are really important in Haskell programming
  • Everything has a “type” (this raised confusion and interest, as expected)
  • Explained that 2 is a number, but that it's also type (yes, it’s a bit of a lie, Int, and defaulting to Integer, and Num a => a, blah, blah, blah. This is fine for the first lesson.).
  • Is 2 a string? No. Is 2 a dog? (giggles) No. Is 2 a missile? (Eliezer got to explain that concept to Gavriella.)
  • print 2 + 3 because of the order of operations (just like math) really is (print 2) + 3, what does that mean?
  • What’s the type of print? Confusion.
  • We’ve discussed functions a lot before, so I pointed out that print is a function that takes a number (here) and returns something else. What is that something else?
  • I introduce the idea of actions. Eliezer got this, Gavriella was more confused. So more humor to explain this.
  • fart = print "Sorry, I farted" lots of giggling. What is the type of fart? Is it a number? No. Is it a dog? No. It’s something that you do, or the computer does. That’s what an action is. (Gavriella translated some words into Hebrew at that point, and the ideas clicked. Got to remember: they’re learning both programming languages and how to learn things in English at the same time.)
  • OK, you can add two numbers together. Does it make sense to add an action and a number together? No. So print 2 + 3doesn’t make sense!
  • Now, what’s print? It’s a function that takes a number and gives you back an action. And that’s how you use functions in Haskell: just stick things next to each other.
  • They figured out really quickly at this point that they needed parentheses to fix the program, and ended up with print (2 + 3).

Today’s Exercise

Note: Somewhere above, I briefly showed them that you could use do notation and put multiple print calls on different lines. No confusion from this at all. Relevant to the exercise:

  • Write a program that print “2 + 3 + 4”, first as a string, and then as a number.

I started them off with:

main = do
  | -- prompt started here

They both got the answer, one of them with a bit of help:

main = do
  print "2+3+4"
  print (2+3+4)

Things to note:

  • They naturally left off the spaces, despite me using the spaces throughout my typing.
  • They never questioned why print "Hello World" resulted in output that kept the double quotes. I’ll have to explain at some point about putStrLn, but that can come much, much later.

Things to Figure Out

  • How much shell do I teach them?
  • What editor will I set them up with?

Next Lesson

I don’t want to plan out what to cover next time too intricately, because I want to experiment with them and bounce things around. I’m thinking about showing them how to create their own functions, maybe with lambda syntax, but I'm not sure.

Coding (social sciences) Haskell (programming language)

Published at DZone with permission of Michael Snoyman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Portfolio Architecture Examples: Retail Collection
  • Modernize Legacy Code in Production: Rebuild Your Airplane Midflight Without Crashing
  • Java: Why Core-to-Core Latency Matters
  • Deployment of Low-Latency Solutions in the Cloud

Comments

Agile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo