Why Python?
Thu, Sep 24, 2015There are a huge number of programming languages out there. You’ve probably heard of one or two, even if you’re not a programmer yourself - Java, C++, Swift, etc. But what are they all about and how do you choose which one to learn?
There’s really not one perfect answer to this question, but personally, I prefer Python for teaching kids for a number of reasons. I’ll go into some of those reasons below, but if I had to boil it down to a few bullet points, they would be these:
- It’s great for beginners
- It’s not a “teaching” language
- It’s very widely used
Programming languages are tools
Programming languages can be thought of as tools in a toolbox. You wouldn’t use a hammer to cut a piece of wood, and likewise a programmer will often choose a particular language based on what type of project they’re working on, or what the other members of their team may be using. Most programmers will learn multiple languages over the course of their careers.
While that may sound daunting, the good news is that programming languages are not like human languages. Learning Italian does not make it any easier to learn Japanese because the two are completely unrelated. Programming languages, however, are all very similar in most respects. Once you’ve learned one, the next one will be much easier - so it makes sense to choose a beginner-friendly language for your first.
Ultimately, learning to code is about learning how to think about problems and how to convince a computer to do what you want it to do. You have to take a given problem or task and break it down into small manageable pieces that a computer can understand. The actual programming language is secondary, and by far the easier part of the learning process.
Python is great for beginners
Beginners need to start out by doing simple things. Learning to code is hard enough when you’ve never been exposed to it before. The more the language can get out of your way and let you focus on the concepts, the better you’ll be able to understand them. Some languages were just never intended to be for beginners (I’m looking at you, Java).
Python was designed from the start to be a readable language, which is one of the things that makes it so friendly for beginners. There are no semicolons or curly brackets to keep track of, so it’s easier to look at and comprehend. Because good formatting is required, it forces the programmer to think about how the code is organized.
For example, here is the code to print the words “Hello, World!” to the screen in Python:
print("Hello, World!")
By comparison, here is what you would need to type for Java:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
Or this, for C:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
puts("Hello World!");
return EXIT_SUCCESS;
}
Beginners are not ready for some of the more advanced concepts required to explain what each of those lines of Java or C does, so most beginner classes are forced to gloss over them with “just type it and you’ll learn why later.” In contrast, in Python it’s easy to do easy things. Especially when teaching children, this is a very important factor.
As another example, let’s look at the loop. Loops are a very important part of programming; they tell the computer to repeat some code over and over. Here’s how you print “hello” five times in Python:
for i in range(5):
print("hello")
Versus Java:
public class Hello {
public static void main(String[] args) {
for(int i=0 ; i < 5 ; i++)
{
System.out.println(“hello");
}
}
}
The C-style loop syntax (initialize; test; update) is very tricky to get right at first - there’s a lot to unpack there. And don’t even get me started on all those curly brackets.
But it’s not only for beginners
A lot of programming curriculum addresses the friendliness problem by using specialized teaching languages that simplify things for the classroom environment. The problem with this solution is that it sets a ceiling on how far students can go; when they reach the limits of the teaching language and want to move on to “real” programming, they are forced to start over with a whole new system.
Python, while very friendly to beginners, is widely used by experts as well. It is very popular both in industry and academia. According to a recent survey, many of the top engineering schools use it (http://cacm.acm.org/blogs/blog-cacm/176450-python-is-now-the-most-popular-introductory-teaching-language-at-top-us-universities/fulltext). It’s also an increasingly popular alternative to expensive systems like Matlab for scientific computing applications.
Another very important point: Python is free and runs on any kind of computer. Because it’s not a commercial product tied to a particular platform, students are not limited by what they might have access to at home/school or required to invest in any expensive software to get started.
All of this means that there is a vast amount of available resources for Python - books, videos, web tutorials, and online courses. The Python community is very large and welcoming to newcomers.
What about Javascript?
Javascript (not to be confused with Java - the two are completely unrelated) is another popular choice for teaching kids programming. Its advantage is its ubiquity: all you need is a web browser, so there’s nothing to install. For that reason, many sites like Khan Academy and code.org have chosen it. However, I find its syntax to be a little less friendly than Python, so it’s not my first choice in the classroom. It would make a great second language for app/game development, though.
Final thoughts
Learning to code is the important thing - which language should be a matter of practicality.
Ultimately, the best answer to the question of what programming language to learn is the one that you will have the most support in. There is a wealth of material on the Internet to help learn any language. However, new programmers, especially kids, often get stuck and just need someone who can help them get over that speed bump. If a student is learning at home and they have an Uncle or Aunt who’s a Java programmer, then that’s going to be a more effective choice than one with no support available.
Over the past few years, I’ve taught hundreds of kids in beginner and intermediate level Python classes and I’ve been very happy with Python as our language of choice.