Wednesday, May 25, 2016

Teaching Programming: What’s the Best Language for Beginners?

teaching programming

Like many of my age and generation, I started learning to program with BASIC. These were the days when you bought magazines full of pages and pages of code for games or basic applications. You spent hours with your friends painstakingly typing these programs into a computer to find there was a typo, or the game didn't work, and then giving up. It was more about hanging out with your friends, whilst your parents felt like you were learning something.

BASIC had flaws, but one thing I liked about it was that the code was clear and verbose. This is why programs took pages to do anything. There is little chance of any language released now having such "wonderful" syntax as (including mandatory line numbers):

5 LET S = 0
10 MAT INPUT V
20 LET N = NUM
30 IF N = 0 THEN 99
40 FOR I = 1 TO N
45 LET S = S + V(I)
50 NEXT I
60 PRINT S/N
70 GO TO 5
99 END

(Thanks to Wikipedia)

But you must admit that, for a beginner, it's clear what's happening.

Years later, I learned "modern" programming via a series of languages including PHP, Lingo, C++, Visual Basic and Java. I'm sure we covered Object Oriented programming, but mostly I remember it being procedural. This wasn't helped by my years working with Drupal, which didn't have solid OOP concepts until version 8.

Fast forward to the present and some of my motivations for this post. For the past months I've been teaching programming to recent Syrian refugees in Berlin, and our language of choice has been Ruby (and Rails).

Is Ruby the Right Language to Teach to Beginners?

Laying aside a recent growing exodus of programmers from using Ruby (that's a whole other story), we (the teachers) are unsure if it was a good choice. The Ruby community is amazingly supportive and welcoming, and that makes many students succeed in learning to program through sheer perseverance and the support of the community.

However, we've noticed that some of the characteristics of Ruby that attracted experienced programmers are actually obfuscating and confusing. I don't want to turn this post into a "Ruby Bash", because that's not what it's supposed to be. I like Ruby, and it's not the only language that has these problems. My recent experience teaching it to absolute beginners has meant that I have practical examples to illustrate my point(s). I also acknowledge that some of these learnings might be due to teaching the wrong topics in the wrong order, or unlearning some of the common tasks experienced programmers undertake, at least in the short term.

Shortcut Tools

Programmers are a little bit lazy --- or, to be more accurate, we like to find ways to reduce repeatedly typing the same boilerplate and instead focus on the important and unique parts of a project. With Rails, scaffolding does just this; with a handful of commands you can have the underpinnings of an MVC application.

But these tools can completely confuse beginners. They don't understand what was just created, and why, where or how it fits together.

Shortcut Syntax

To an experienced programmer, writing this …

(0..100).each {
  print i
}

… instead of this …

var i;
for (i=0;i<100;i++) {
  print i;
}

… is an amazing and sensical shortcut. In fact, it's efficient: there's no need to initialize a variable or write all that horrible semi-colon separated syntax. But think about it from a beginner's perspective. In the Ruby example, the only words that really make sense are each and print. What are the rest actually doing? It's not to say that a student can't learn these concepts, but in some respects, whilst learning, the second example is clearer and actually shows a student what's happening.

"Do what you like" languages

At one time, there was a trend towards languages that let you write casually --- not having to worry about variable types and so forth. This popularity seems to be waning --- or at least, is increasingly being supplemented by much stricter languages. These have advantages of speed and efficiency, but I do wonder if it's also a case of changing trends. Languages that force you to make certain linguistic steps may take longer to learn, but there's less "grey area" around what is and isn't possible.

Continue reading %Teaching Programming: What’s the Best Language for Beginners?%


by Chris Ward via SitePoint

No comments:

Post a Comment