Target age range: 8-14

This is part 1 of some advice and links to help aspiring programmers get an idea of what learning to program is like.

We don't start right off with how to program -- there are plenty of websites that will teach you about the syntax and semantics of programming languages, and how to install the software tools that allow you to get started.

Rather, this is a talk about the mindset of a programmer and of how programmers approach their craft. It's here to inform you about what the discipline is like, and to help you determine whether it's the right path for you.

If you like that advice, then there are some pointers to places that you can start looking at right away to learn about the basics of programming.

So you want to learn programming?

First, a basic reality check: programming computer software is hard work.

While every person can be expected to do some hard work in their life, you should consider whether programming is the right type of hard work for you. It means long hours in front of a desk, sometimes making little or no progress on your current task. It can mean spending those hours frustrated by some bug or problem with your code that is making it misbehave. Those hours are the daily hours that (in your youth) you might have devoted to other activities like playing outside, video games, watching movies, or going to the store with your friends.

So understand that programming takes a lot of time. If you're young, this isn't such a big deal. You have plenty of time as a young person to attend to schoolwork and pursue your own interests. But, it's like anything that you enjoy: if you want to get good at it, then you forego some amount of time spent on other things in favour of your new interest.

This is a natural, although usually people don't spend this kind of focus on a career pursuit until later in life. Because programming is largely self-taught and doesn't follow any particular curriculum, this means that it's the type of career activity that you can start early and develop at your own pace.

All that said, programming is very rewarding for several reasons:

  • There are lots of different skill levels and areas: it's not too difficult to find something that's right for you.
  • Many projects can be done by one person alone or a small team all by themselves.
  • There's lots of help available from other programmers for free on the internet; you just have to spend the time reading it. Even later in your career, you'll still rely heavily on Q&A websites like StackOverflow to get help on specific topics. Don't be ashamed of this! Asking the right questions -- even ones posed to yourself -- is a fundamental and valuable skill.
  • It connects with other aspects of society like: social media, gaming, business, science, and engineering. If you become interested in any of these things, eventually you'll be able to find software libraries that will do something for you in one of these areas. You can also find software that will provide a programming interface for you to write extensions and mods.
  • It pays reasonably well and there is lots of demand for it. There will probably be lots of demand for programmers for quite a few decades.
  • It is generally not hard on your health like other types of work.
  • You can sometimes work remotely - meaning that you work from home on a project that is on an internet server elsewhere in the world. This also means that you develop a built-in flexibility to live and work in a wider choice of places, unlike traditional occupations that require you to commute to work every day and live nearby.

The secret to being successful at programming is to set small achievable goals for yourself and to learn to appreciate and treasure those small achievements.

That's it. Those small achievements will become something bigger, eventually. Just try not to frustrate yourself with overwhelming complexity, and try not to tell yourself that you're just bad at it when something goes wrong. Programming is challenging for everyone that tries it, and you won't be any different.

Keep that in mind and you'll get back on the horse each and every time you've fallen off (or been thrown off).

Ok, it sounds interesting. Where do I begin?

Every learning domain has its fundamentals. For programming, the important fundamental concepts are:

  • Logic, which can be thought of as a type of simple math.
  • Control Flow, or sequences of executed steps and their results.
  • Thinking of questions about how to get things done reliably, and why those methods work.
  • Using a search engine like Google to help find answers to those questions.

Typing quickly and accurately is also useful. Especially later if you start working on larger programs and want to work quickly. You don't have to reach any given level of typing speed or accuracy right away, just keep in mind that it's something that you want to practice and improve. You'll automatically get better at it if you take a few lessons when you're young, and use those skills to type notes and documents for school.

The first two points are so important that there are even small programming languages and toolkits that are dedicated to helping new learners acquire and master the concepts.

Logic and Control Flow

To learn about logic and control flow, try out Scratch from MIT.

Scratch is a great platform because you don't need to start writing or typing right away. Instead, they let you create small sequences of actions by connecting blocks. The blocks are colour-coded according to their role within the sequence.

Here's a Scratch program written with just 3 blocks.

Let's ask: what does this program do?

When the program runs, the topmost and outermost block (looking at the top and left-hand edge) will get its chance to run. Here, I've used a "forever" block as the outermost block. This block does one simple thing: it runs an inner control block, and when that inner block is finished, the forever block simply runs it again.

And again. And again. FOREVER 😀.

The forever block is important because it will repeat execution of that inner block as long as our program is running. That means we can put other blocks inside it, and Scratch will keep on running those blocks over and over. So the forever block is a very useful outermost block for a Scratch program to have.

Inside the forever block, I put an "if/then/else" block. It also does one simple thing. When it starts at its top, it checks if a condition is true. If that condition is true, then the first block under "then" will run. If the condition is not true, then the second block under "else" will run. (I've left the second block as an empty socket, so if the condition is not true, nothing will happen.)

You can see that I've put a <mouse down> condition in the condition block. This seems to be Scratch's shorthand for the condition that "the mouse button is down". I could have put any other Scratch condition in there, as long as it fits that angled socket shape. But you need to have a condition, otherwise the if/then/else block won't do anything.

So, this if/then/else block just checks if the mouse button is down, and if it is, then it runs its first control block under "else". Here, this plays a Meow sound.

So to recap, this program loops forever, checking over and over if the mouse button is down. If it is, then the Meow sound is played in the speaker.

Believe it or not, this is a basic template for all kinds of computer programs. Lots of games and animations work this way: they have an outer loop that runs "forever", and inside that loop they do some checking to see what events have happened, and then they respond to those events appropriately.

So, you've just taken a peek at a simple program that mimicks the basic behaviour of a wide variety of other programs.

Scratch makes this a bit easier by giving you blocks of different sizes and shapes that you can combine to create more complicated programs and animations.

Keeping things simple: what's a "Hello World" program?

When experienced programmers want to learn a new language or a new programming interface, they don't start off by planning to something complicated and difficult, nor one that will require a lot of time and effort.

Instead, they start by trying to implement the minimum amount of functionality that uses whatever new technology they are learning. This is often called a "Hello, world" program. It's called this because the simplest thing you can do is usually to print some text or display the result of some computation on the screen. By tradition, programmers usually display the text "Hello, world!" or something like that when trying out some new technology.

So, if I was learning the Javascript language or Node.js (which is a popular Javascript framework), I would focus on reading just the documentation and creating just the files that I'd need for just printing the message "Hello, world!" on the screen.

And that's all.

By setting your goals small and taking small steps, you build a sequence of reliable foundations upon which to try new things. If you already have a program that prints a small bit of text on the screen, your next step might be queue the user for a reply to that text. So to build out that second part, you'd ask the question "How do I collect user input?" and you'd already know that your previous solution to printing a bit of text on the screen would already work.

If for any reason you should break things during your implementation of the "user input collection" phase of your project, you can always feel safe knowing that you can return to a previous version of your first phase where you only printed text on the screen. Just remember to save several copies of your work!

Tell me how to actually code!

Ok, if you read this far, you need some specific direction. Head over to Scratch and make an account if you don't have one.

You need to take a look at some of the existing animations that other people have created so that you know what the general capabilities of Scratch are. Spend at least a half an hour or more perusing other people's work. Remember that some of those projects are built by people with a lot more experience than you, and that your initial creations will be simpler.

Another reality check: you won't be creating massive games or working with 3D graphics and databases with this platform -- it's designed to let you experiment with basic programming constructs and to allow you to make some interactive creations.

Now go to the Ideas page and go through the Getting Started tutorial.

After you've watched that, you need to go through the other walk-through videos that explain the different aspects of Scratch.

One of the best first projects with Scratch is an animation. Scroll down a bit on the Ideas page and look for the part that teaches you to animate. These don't require a lot of logic to get going, and you can work with the graphics and sounds that Scratch offers to create something that has some motion and sound without needing your program to interact with the user.

Set some basic goals for yourself and follow the tutorials. Think of animations that you'd like to create, and try to pick things that require you to do something that you don't know yet.

This is the part of the article where I go away and you get to learn about devoting a lot of time to a subject. By the time you read Part 2 of this series, hopefully you'll have already tried a few scratch animations and may have even ventured into the realm of responding to user input. In Part 2, we'll look at using some of the more advanced features of Scratch, like storing information in variables and creating more complicated conditions and expressions.

But before you get there, you have to do some work!

© 2021 michaeljoya.com