
Writing Computer Code
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
More details
Other editions
Additional editions

Persons
Content
PROJECT 1
BECOMING A PROGRAMMER
COMPUTERS CAN'T DO THINGS ON THEIR OWN. They need a computer program to tell them what to do, and they need people to write those computer programs. The people who write the code to make computers do all sort of things are called computer programmers.
WHAT IS PROGRAMMING?
A computer program is a group of instructions that can be understood and followed by a computer. Another name for a computer program is software. Computer programming, also known as coding, is what we call it when we write these instructions.
Figure 1-1 shows a computer program.
Figure 1-1: The computer program you'll make in this book!
Right now, this computer code may look confusing, but after you've read this book, you'll understand how to read it and even write it yourself!
THE WOMEN WHO INVENTED PROGRAMMING
Electronic computers were first invented in the 1930s. But it was in the middle of the 1800s when the first computer program - a set of instructions designed to be carried out by a machine - was written.
The author of the first computer program - and the world's first computer programmer - was a woman named Ada Lovelace. She was a mathematician who lived in England. Ada imagined that computers would be able to do all the things we use computers for today, including working with words, displaying pictures, and playing music. Her unique understanding earned her the nickname "The Enchantress of Numbers." We're guessing your nickname isn't as rad as that.
The computer that Ada Lovelace wrote programs for didn't look anything like the computers of today. Instead of a plug or battery, it had a crank! Check out this photograph of Charles Babbage's Difference Engine, one of the very first computers.
Photograph courtesy of Jitze Couperus (https://commons.wikimedia.org/wiki/File:Babbage_Difference_Engine_(Being_utilised).jpg)
In order for computer programs to be converted into machine language, we need to use compilers. Compilers are programs used to convert programming languages into machine language. The very first compiler was created by Grace Murray Hopper in 1944. Her invention led to computer programs being able to run on different types of computers, and eventually gave birth to JavaScript. Grace Hopper is also the inventor of the term debugging, for fixing problems in computer programs. This term was inspired by the removal of an actual moth from an early computer. Grace Hopper became known as "The Queen of Software" or "Amazing Grace" for her contributions to modern computing. (What can we say? Nicknames were just cooler back then.)
The computers that Grace Hopper worked on used electricity (not cranks), and they were huge, as you can see in this photograph, which shows the Colossus computer. Colossus was the first programmable electronic computer.
Photograph courtesy of Bletchley Park Trust/Science & Society Picture Library (www.flickr.com/photos/101251639@N02/9669449367)
The computers of today are much more powerful than ever before. It used to take a whole room of computers to do what we can now do with even the smallest computer. One thing all computers have in common, no matter how powerful, is that they need computer programs to do anything and they need computer programmers to write these programs.
Computer programs help people to do many things, including the following:
- Playing music and videos
- Performing scientific experiments
- Designing cars
- Inventing machines
- Playing games
- Controlling robots
- Guiding satellites and spaceships
- Creating magazines
- Teaching people new things
Can you think of other things that computers can do?
All computer programs begin with an idea. Before you start writing any code, it's important to think about what you want your program to do. Use your imagination and dream big!
Here are some helpful questions to think about before you begin coding:
- What will my program do?
- Who will use my program?
- Why will they use my program?
- Where will they use my program?
- How will they use my program?
HOW CAN YOU TALK TO COMPUTERS?
Every computer program is written using a computer programming language. Programming languages allow you to write instructions that can be translated (or compiled) into machine language. These programming languages are eventually turned into binary codes, which use zeros and ones to form letters, numbers, and symbols that can be put together to perform tasks.
At the heart of every computer is a central processing unit (CPU), shown in Figure 1-2.
Source: https://commons.wikimedia.org/wiki/File:Cpu.jpg
Figure 1-2: At the heart of every computer is a CPU.
The CPU is made up of millions of tiny, very fast switches (called transistors) that can be on or off. The position of these switches determines what the computer will do. Software, written by programmers, tells these switches when to turn on or off by using binary codes.
Every single thing that a computer does is the result of a different combination of many zeros and ones. For example, to represent a lowercase letter a, computers use the following binary code:
0110 0001
Each zero or one in a binary number is called a bit, and a combination of eight bits is called a byte. When you hear the words kilobyte, megabyte, and gigabyte used to tell how big a file is, what that means is the number of bytes it takes to store the file.
WRITING NUMBERS IN BINARY CODE
Do you want to learn to count like a computer? We'll show you how to write any number between 0 and 255 in binary code. For this example, we'll write the number 150 in binary code.
- Write the following numbers horizontally at the top of a piece of paper:
128
64
32
16
8
4
2
1
These numbers are your binary cheat sheet.
- Underneath these numbers, write the number that you want to convert to binary, which is 150.
- Start with the first number you wrote on your paper, 128. If this number fits inside of 150, write a 1 under it. If it doesn't fit inside of 150, write a 0 under it.
Because 128 can fit inside of 150, put a 1 under the 128.
128
64
32
16
8
4
2
1
1
- Subtract the number 128 from the number you're writing in binary code (150): 150 - 128 = 22. Cross out the 150 that you wrote down and write down 22.
- Compare the remainder to the next number in your binary cheat sheet, 64. Does 64 fit inside of 22? It doesn't, so write a 0 under 64 and move on to the next number in the cheat sheet, 32.
- Because 32 doesn't fit inside of 22, write a 0 under the 32, and move on to the next number, which is 16.
- Ah ha! 16 does fit inside 22! Write a 1 under the 32 and then subtract 16 from 22: 22 - 16 = 6. Cross out the 22 and write down 6.
- Take a look at the next number. Does 8 fit inside of 6? It doesn't, so write down a 0 and move on to the next number.
Continue doing these steps until you reach the last number of the binary cheat sheet. In the end, you should have the following:
128
64
32
16
8
4
2
1
1
0
0
1
0
1
1
0
Now you know that 10010110 is the binary code for 150.
Table 1-1 lists the most common storage sizes.
TABLE 1-1 HOW MANY BYTES IS THAT?
Name
Number of Bytes
What It Can Store
Kilobyte (KB)
1,024
Two to three paragraphs of text
Megabyte (MB)
1,048,576
800 pages of a...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.