Category Archives: Introduction

Hello World

Writing something meaningful has always been on my wishlist of the things I’ll do once I retire, although that something has never been materialized: the more I think about it, the less I actually do anything with it. Writing seems a daunting task to take on, the amount of preparation work required itself is big enough to keep me away from even starting it, with the fact being I don’t even know what to prepare. :-)

So this thinking remains a wish, till a few days ago Frank said he wanted to learn how to program. Maybe I can share what I’ve learned over the past years of programming at work?

For all those who write software, ‘Hello World’ is the official starting point, so here it goes …

 

Hello Programming

Programming is about asking computer to do what we want it to do. Now follow me, “hey Mr. computer, please say hello” …

Well, nothing happens, no matter how polite I am, the computer just sits there doing nothing, or rather, doing its own thing.

To let computer actually do something, we need to be formal, we need to put everything in writing. This writing is called programming.

The above is not entirely true though, computer also takes voice command, for example with ‘Ok Google’ or ‘SiRi’, you can ‘tell’ computer what to do. Although what computer can do in this case is very limited today, this certainly will change. Maybe some day in the future, the programming can be entirely achieved verbally. For now though, we will focus on programming in writing. And hopefully our wonderful programming technique in writing will greatly shorten the time to that future, both ‘Ok Google’ and ‘SiRi’ are programs written by engineers after all.

Back to writing, there is a few questions we need to answer,

  • what do we use to write?
  • what language shall we write in?
  • how do we let computer read our writing?

Answering all that, we’ll have something in writing that the computer can understand, and hopefully computer will actually do what it reads.

This is something in writing is called Program.

To answer all those questions, let’s first take a step back, and see who will actually read our Program and do the things we write down there.

Computer, of course.

That is correct, but there is more. Our program can be read and understood by many more, for example, phone, tablet are the two where we can download program to. There is even more, music player, video game console, TV,  car, many of the electrical things around us can read and run program.

Computer is a little bit special, it understands the Program we write, it is also the tool we use to write our program with. So we will start with Computer …

Hello Computer

From Wikipedia,

A computer is a general-purpose device that can be programmed to carry out a set of arithmetic or logical operations automatically. Since a sequence of operations can be readily changed, the computer can solve more than one kind of problem.

That seems quite complicated, if I have to know all that to use computer to do my math, I probably will just count on my fingers, or maybe a calculator, if not an abacus.

Let’s describe computer in a more user understandable way. Computer is a robot, it will do exactly what we ask it to do, assuming we speak the language Computer understands of course. Computer ‘listens’ to us through keyboard/mouse, computer ‘tells’ us what it has done through screen, which is often called monitor. Computer ‘friends’ with other electrical devices through its ports: USB, serial etc.

Computer also likes to be social, they ‘talk’ to each other through network, and often exchanges lots of information with each other without us even knowing.

And of course Computer needs power, which is available either from a wall plug or the battery that comes with it.

That is the outside of it, Computer has magic parts inside as well.

First, Computer has storage to store our files such as pictures, movies, and the program that we are going to write. This storage is usually called disk or drive. The important thing for storage is that we can trust them that our files will not go away even if computer lost power.

Then there is a part called memory, so Computer can temporarily hold stuff there without going to actual storage place. You have a full shelf of story books at home,  you’ll still want to put a few of your favourites in your backpack. It is much easier and faster to check out book from your backpack than taking a trip back to home to get it. The key to memory is access speed, but anything Computer puts in memory gets lost when computer lost power. We’ll talk more about memory when we get to actual programming part.

The heart of Computer is called CPU, the Central Processing Uint, this is the big boss, who manages disk and memory, and takes our programming input and commands the other parts of the Computer to do the job.

CPU itself knows about how to work with the other part of the Computer, but does not know how to get the actual job done. Our brain knows how to drive our legs to walk, but we need to learn to get instructions in order to plan a trip to the Great Wall China from Chicago US. CPU gets instructions from its super boss, you, the programmer.

There are many instructions CPU understand, to read or write disk, to read keyboard input and monitor mouse movement, to display text and graphics on monitor, to play sound etc. It is a big task to learn to understand all those instructions all at once, although eventually we’ll learn to program them directly by sending instructions to CPU to drive different part of Computer, we do not start that way. Instead, we start with a piece of software written by other programmers.

This piece of software knows to send the right instructions to CPU to do basic things. For example, if we press letter ‘T’ on keyboard, this software informs the display to also display ‘T’ at the right place. If we move the mouse, this software knows to move the cursor accordingly on screen display. When we are tired, this software will take our request and politely shut down the Computer itself.

Before we start our programming adventure, we have a few words to say about this important piece of software.

This software is called Computer Operating System, or OS …

Hello Operating System

Operating System, is the software that makes Computer the robot. Without OS, Computer would be just a piece of paper weight with different metal or plastic parts here and there. OS also provides support to extend the capability of the robot itself, by allowing programmer to further program on it!

OS does many jobs, such as taking our keyboard and mouse input, display information on screen, receive and send data from/to network etc. OS also manages users of Computer, to determine who can use computer when. Ok, I take the ‘when’ part back, Daddy is doing that part, for now.

Out of the many things OS can do, the one thing that interests us programmer is its capability to run the program we write. More interestingly it can run more than one program at the same time.

To run our program, or any program, it is common that we simply pick the program and click on it. To go a little deeper on this, Program is basically a collection of instructions CPU understands. This program needs to be stored somewhere on Computer. Correct, you guessed it, the program is stored in disk. After clicking, in order for CPU to quickly access its next instruction from this program, the program is loaded to memory from disk,  sometime as a whole, sometime only part of it.  After that, CPU runs the instructions one after the other, and all the magic starts.

Clicking is one way to run our program, OS provides us that capability through the graphical interface, you browse to what you want to run, and click. Easy?

That is the graphical way, there’s another way to tell OS to run our program, we call it ‘command line’, because this way we can give OS commands on a line-by-line basis. OS provides us command line access through a program called terminal. So you can open a terminal, type commands, or find our program and run from there.

Wait, it is so easy to click and go, why bother with those extra steps to use command line?

That can be a personal preference, but what if you are told that through command line you can search and manage your files more quickly and easily, and, you can remotely run your program, for example, start your program on your home computer, from your laptop or ipad while you are climbing the Great Wall? And, through command line interface, you can do a lot more than just clicking around.

Command line is a powerful tool for programmer, let’s keep that in mind.

We’ve talked about what OS does and what interface it provides to us in order to run program. But what is this magic piece of OS software called?

There are different flavours of them.

Three among them are well known for Computer world. Windows, OS X, and Linux. There are other Operating Systems for devices, such as Android, iOS etc, but we’ll focus on Computer side.

Linux? never heard of it.

Now you do, and that’s the OS we will be using to learn programming.

Why? read the following text from Wikipedia,

Examples of popular modern operating systems include Android, BlackBerry 10, BSD, Chrome OS, iOS, Linux, OS X, QNX, Microsoft Windows, Windows Phone, and z/OS. The first eight of these examples share roots in UNIX.

Yes, we want to start our learning with something that has a more popular root.

And, because Daddy says so. :-)

Let’s start by setting up a Computer with Linux OS …