
- •About the Author
- •Dedication
- •Author’s Acknowledgments
- •Contents at a Glance
- •Table of Contents
- •Introduction
- •Who Should Buy This Book
- •How This Book Is Organized
- •Part I: Programming a Computer
- •Part II: Learning Programming with Liberty BASIC
- •Part III: Advanced Programming with Liberty BASIC
- •Part VI: Internet Programming
- •Part VII: The Part of Tens
- •How to Use This Book
- •Foolish assumptions
- •Icons used in this book
- •Why Learn Computer Programming?
- •How Does a Computer Program Work?
- •What Do I Need to Know to Program a Computer?
- •The joy of assembly language
- •C: The portable assembler
- •High-level programming languages
- •Database programming languages
- •Scripting programming languages
- •The program’s users
- •The target computer
- •Prototyping
- •Choosing a programming language
- •Defining how the program should work
- •The Life Cycle of a Typical Program
- •The development cycle
- •The maintenance cycle
- •The upgrade cycle
- •Writing Programs in an Editor
- •Using a Compiler or an Interpreter
- •Compilers
- •Interpreters
- •P-code: A combination compiler and interpreter
- •So what do I use?
- •Squashing Bugs with a Debugger
- •Writing a Help File
- •Creating an Installation Program
- •Why Learn Liberty BASIC?
- •Liberty BASIC is easy
- •Liberty BASIC runs on Windows
- •You can start using Liberty BASIC today
- •Installing Liberty BASIC
- •Loading Liberty BASIC
- •Your First Liberty BASIC Program
- •Running a Liberty BASIC program
- •Saving a Liberty BASIC program
- •Getting Help Using Liberty BASIC
- •Exiting Liberty BASIC
- •Getting input
- •Displaying output
- •Sending Data to the Printer
- •Storing Data in Variables
- •Creating a variable
- •Assigning a value to a variable
- •Declaring your variables
- •Using Constants
- •Commenting Your Code
- •Using variables
- •Working with precedence
- •Using parentheses
- •Manipulating Strings
- •Declaring variables as strings
- •Smashing strings together
- •Counting the length of a string
- •Playing with UPPERCASE and lowercase
- •Trimming the front and back of a string
- •Inserting spaces
- •Yanking characters out of a string
- •Looking for a string inside another string
- •Using Boolean Expressions
- •Using variables in Boolean expressions
- •Using Boolean operators
- •Exploring IF THEN Statements
- •IF THEN ELSE statements
- •Working with SELECT CASE Statements
- •Checking a range of values
- •Checking a relational operator
- •Boolean expression inside the loop
- •Looping a Fixed Number of Times
- •Counting with different numbers
- •Counting in increments
- •Anatomy of a Computer Bug
- •Syntax Errors
- •Fun with Logic Errors
- •Stepping line by line
- •Tracing through your program
- •Designing a Window
- •Creating a new window
- •Defining the size and location of a window
- •Adding color to a window
- •Putting Controls in a Window
- •Creating a command button
- •Displaying text
- •Creating a check box
- •Creating a radio button
- •Creating text boxes
- •Creating list boxes
- •Creating combo boxes
- •Creating group boxes
- •Storing Stuff in Text Files
- •Creating a new text file
- •Putting stuff in a text file
- •Adding new stuff to an existing text file
- •Retrieving data from a text file
- •Creating a new binary file
- •Saving stuff in a binary file
- •Changing stuff in a binary file
- •Retrieving stuff from a binary file
- •Creating a Graphics Control
- •Using Turtle Graphics
- •Defining line thickness
- •Defining line colors
- •Drawing Circles
- •Drawing Boxes
- •Displaying Text
- •Making Sounds
- •Making a beeping noise
- •Playing WAV files
- •Passing Data by Value or by Reference
- •Using Functions
- •Defining a function
- •Passing data to a function
- •Calling a function
- •Exiting prematurely from a function
- •Using Subroutines
- •Defining a subroutine
- •Passing data to a subroutine
- •Calling a subroutine
- •Exiting prematurely from a subroutine
- •Writing Modular Programs
- •Introducing Structured Programming
- •Sequential instructions
- •Branching instructions
- •Looping instructions
- •Putting structured programming into practice
- •The Problem with Software
- •Ways to Make Programming Easier
- •Breaking Programs into Objects
- •How to use objects
- •How to create an object
- •Creating an object
- •Starting with a Pointer
- •Defining the parts of a linked list
- •Creating a linked list
- •Managing a linked list
- •Making Data Structures with Linked Lists
- •Stacks
- •Queues
- •Trees
- •Graphs
- •Creating a Record
- •Manipulating Data in Records
- •Storing data in a record
- •Retrieving data from a record
- •Using Records with Arrays
- •Making an Array
- •Making a Multidimensional Array
- •Creating Dynamic Arrays
- •Insertion Sort
- •Bubble Sort
- •Shell Sort
- •Quicksort
- •Sorting Algorithms
- •Searching Sequentially
- •Performing a Binary Search
- •Hashing
- •Searching by using a hash function
- •Dealing with collisions
- •Picking a Searching Algorithm
- •Choosing the Right Data Structure
- •Choosing the Right Algorithm
- •Put the condition most likely to be false first
- •Put the condition most likely to be true first
- •Clean out your loops
- •Use the correct data types
- •Using a Faster Language
- •Optimizing Your Compiler
- •Programming Computer Games
- •Creating Computer Animation
- •Making (And Breaking) Encryption
- •Internet Programming
- •Fighting Computer Viruses and Worms
- •Hacking for Hire
- •Participating in an Open-Source Project
- •Niche-Market Programming
- •Teaching Others about Computers
- •Selling Your Own Software
- •Trying Commercial Compilers
- •Windows programming
- •Macintosh and Palm OS programming
- •Linux programming
- •Testing the Shareware and
- •BASIC compilers
- •C/C++ and Java compilers
- •Pascal compilers
- •Using a Proprietary Language
- •HyperCard
- •Revolution
- •PowerBuilder
- •Shopping by Mail Order
- •Getting Your Hands on Source Code
- •Joining a Local User Group
- •Frequenting Usenet Newsgroups
- •Playing Core War
- •Programming a Battling Robot
- •Toying with Lego Mindstorms
- •Index
- •End-User License Agreement

Chapter 1: Learning Computer Programming for the First Time |
13 |
How Does a Computer Program Work?
Computers don’t do anything without someone telling them what to do, much like the average teenager. To make the computer do something useful, you must give it instructions in either of the following two ways:
Write a program, which tells a computer what to do, step-by-step, much as you write out a recipe.
Buy a program that someone else has already written that tells the computer what to do.
Ultimately, to get a computer to do something useful, you (or somebody else) must write a program.
A program does nothing more than tell the computer how to accept some type of input, manipulate that input, and spit it back out again in some form that humans find useful. Table 1-1 lists some common types of programs, the type of input that they accept, and the output that they produce.
Table 1-1 |
Input and Output for Various Programs |
||
Type of |
Input |
What the |
Output |
Program |
|
Program Does |
|
Word |
Characters you |
Formats the text; |
Displays and |
processor |
type from the |
corrects spelling |
prints neatly |
|
keyboard |
|
organized text |
|
|
|
|
Game |
Keystrokes |
Calculates how fast |
Moves a |
|
or joystick |
and far to move a |
cartoon figure |
|
movements |
cartoon figure |
on-screen |
|
|
on-screen |
|
|
|
|
|
Stock-market |
Current and past |
Tries to recognize |
Predicts the |
predictor |
prices for stocks |
trends in a stock’s |
future price of |
|
|
price fluctuations |
a stock |
Missile guidance |
Current location |
Calculates how to |
Corrects the |
program |
of the missile and |
make the missile’s |
trajectory so |
|
the target |
location and the |
that it stays |
|
|
target’s location |
aimed at the |
|
|
coincide |
target |
|
|
|
|
(continued)

14 |
Part I: Programming a Computer |
Table 1-1 (continued)
Type of |
Input |
What the |
Output |
Program |
|
Program Does |
|
Optical character |
Text from |
Recognizes |
Converts |
recognition (OCR) |
a scanner |
shapes of |
scanned text |
|
|
characters |
into a text file |
|
|
|
that a word pro- |
|
|
|
cessor can edit |
|
|
|
|
Web browser |
HyperText Markup |
Converts the HTML |
Displays Web |
|
Language (HTML) |
codes into text and |
pages on- |
|
codes on other |
graphics |
screen |
|
computers |
|
|
|
|
|
|
Programming is problem-solving
Essentially, a program tells the computer how to solve a specific problem. Because the world is full of problems, the number and variety of programs that people can write for computers is practically endless.
But to tell a computer how to solve one big problem, you usually must tell the computer how to solve a bunch of little problems that make up the bigger problem. If you want to make your own video game, for example, you need to solve some of the following problems:
Determine how far to move a cartoon figure (such as a car, a spaceship, or a man) on-screen as the user moves a joystick.
Detect whether the cartoon figure bumps into a wall, falls off a cliff, or runs into another cartoon figure on-screen.
Make sure that the cartoon figure doesn’t make any illegal moves, such as walking through a wall.
Draw the terrain surrounding the cartoon figure and make sure that if the cartoon figure walks behind an object such as a tree, the tree realistically blocks the figure from sight.
Determine whether bullets that another cartoon figure fires are hitting the player’s cartoon figure. If so, determine the amount of damage, how it affects the movement of the damaged cartoon figure, and how the damage appears on-screen.
The simpler that the problem is that you need to solve, the more easily you can write a program that tells the computer how to work. A program that

Chapter 1: Learning Computer Programming for the First Time |
15 |
displays a simple Ping-Pong game with two stick paddles and a ball is much easier to write than a program that displays World War II fighter airplanes firing machine guns and dropping bombs on moving tanks, while dodging anti-aircraft fire.
Programming isn’t difficult; it’s just time-consuming
Programming really isn’t that difficult or mysterious. If you can write step-by- step instructions directing someone to your house, you can write a program.
The hardest part about programming is identifying all the little problems that make up the big problem that you’re trying to solve. Because computers are completely stupid, you need to tell them how to do everything.
If you’re giving a friend instructions to get to your house, for example, you may write down the following information:
1.Go south on Highway I-5.
2.Get off at the Sweetwater Road exit.
3.Turn right at the light.
4.Turn into the second driveway on the left.
Of course, if you try giving these instructions to a computer, the computer gets confused and wants to know the following additional information:
1.Where do I start and exactly how far south do I drive down Highway I-5?
2.How do I recognize the Sweetwater Road exit, and how do I get off at this exit?
3.After I turn right at the light, how far to the right do I turn, and do you mean the traffic light or the street light on the corner?
4.After I turn into the second driveway on the left, what do I do next? Park the car? Honk the horn? Gun the engine and accelerate through your garage door?
You need to tell computers how to do everything, which can make giving them instructions as aggravating and frustrating as telling children what to do. Unless you specify everything that you want the computer to do and exactly how to do it, the computer just plain doesn’t do what you want it to do.