Beginning Programming All-in-One For Dummies. Wallace Wang
FIGURE 3-1: Programming in Scratch means connecting visual building blocks together.
Just keep in mind that Scratch is meant to teach programming principles, but it doesn’t let you create commercial applications. When you learn C or any C-derived language like C#, Python, or Swift, you’re forced to learn programming principles and language syntax at the same time. When you learn Scratch, you can just focus on learning programming principles so you’re learning one thing at a time.
When you feel ready, you can take your knowledge of programming principles and then tackle the second problem of learning a particular language syntax. So, learning programming through Scratch is a two-step process, while learning programming through a language like C is a massive, and possibly overwhelming, single-step process.
Programming robots with LEGO Mindstorms
Kids love building things with LEGO building blocks, so to encourage kids to build actual working robots, LEGO released a LEGO robot-building kit called Mindstorms. Not only can you build a working robot with LEGO building blocks, but you can also program the robot using the Mindstorms programming language.
To write a program, you don’t have to type a thing. Instead, you arrange icons that represent different types of actions your robot can do, such as move forward
or respond to a light
, as shown in Figure 3-2. After writing the program on your computer, you load that program into your LEGO robot and watch it go.
FIGURE 3-2: LEGO Mindstorms programming connects visual building blocks together to control a working robot.
By using LEGO Mindstorms, anyone can figure out both programming skills and robot-making skills. Unlike other programming languages, LEGO Mindstorms lets you see your working program in action as a walking, rolling, or crawling LEGO robot.
Learning object-oriented programming with Alice
Nearly all modern programming languages support object-oriented programming. Unfortunately, figuring out object-oriented programming can be difficult, especially for beginners who already have enough trouble just figuring out how to program a computer.
To help beginners understand object-oriented programming, Carnegie Mellon University created a free programming language dubbed Alice (www.alice.org
). To make programming fun and teach object-oriented principles at the same time, Alice lets beginners write simple programs to animate characters onscreen, as shown in Figure 3-3.
FIGURE 3-3: An Alice program creates an animated character onscreen and moves it around.
When you write an Alice program, your commands create an animated character onscreen. Then you need to write additional commands to tell that animated character how to move to create a simple story. In the process of telling the animated character how to move, you wind up discovering both how to program and how to use object-oriented principles, while having fun in the process.
Like most instructional programming languages, Alice programming uses plain English commands, like move forward
or play sound
. By using simple commands, Alice lets you focus on understanding the principles of object-oriented programming without getting bogged down in understanding the peculiar syntax of a specific programming language.
Programming a killer robot
Studying how to program by controlling a LEGO robot can be fun (see “Programming robots with LEGO Mindstorms,” earlier in this chapter), but to combine the thrill of controlling a robot with the joy of playing a video game, computer scientists have also created games that let you write a simple program for controlling a battling robot, as shown in Figure 3-4.
FIGURE 3-4: Using a battling robot to study programming can make programming more exciting.
Instead of writing a program just to control a robot, these games force you to write a program to move a robot onscreen, search for other robots nearby, and then attack those other robots with a cannon.
After you finish your program, you can see the results by watching your robot battle another robot in a gladiator-style battle. Write a “good” program, and your robot can defeat another robot. Write a “bad” program, and your robot gets blasted into chunks of (virtual) charred metal.
To program a “battling robot,” use a simplified version of a popular programming language, such as C, C++, or Java. That way, not only do you figure out the basics of a popular programming language, but you also can start writing “real” programs that actually do something interesting right from the start. Table 3-1 lists some popular “battling robot” programming games.
TABLE 3-1 Popular “Battling Robot” Programming Games
Program | Language Used | Where to Find It |
---|---|---|
C++ Robots | C++ |
www.gamerz.net/c++robots
|
Crobots | C |
https://crobots.deepthought.it
|
Robocode | Java |
https://robocode.sourceforge.io
|
Curly-Bracket Languages
Whether you learn about programming using a simpler language or jump right in and start with C, you'll eventually need to learn one of the more popular programming languages based on C. This family of related languages is known as the curly-bracket language family.
The curly-bracket language family gets its name because all the languages use curly brackets to define the start and end of a block of commands, like this:
#include <stdio.h>void main(){ printf("Notice how the curly brackets\n"); printf("identify the beginning and end\n"); printf("of your commands?\n");}
Rather than use curly brackets, programming languages like Ada or Pascal use descriptive