University of Florida

Institute of Food and Agricultural Sciences
   Home  |  Objectives  |  Agents  |  Parents  |  Youth  |  Contact Us  | 
 |  


Programming 101: The Basics

Project Details

     Computers now take many forms and are available in many places in people's lives. From special purpose computers, such as those that monitor operation of automobiles, through general purpose computers such as those used in homes and offices, to specialized computers constructed to solve very large problems in mathematics and science, all computers perform tasks directed by instructions (software, programs) that someone wrote. People in many walks of life can simply purchase software to assist in their work. Others, whose work is more specialized or who need specific variations in the operation of the computer, need to be able to construct software for their own purposes.

     Software development, or computer programming, now takes many forms. In this project, either "higher-order languages" or "visual programming" may be used. In both of these, a piece of software exists to allow human-friendly forms of expression to be translated to the highly specific form of instructions to which computers actually respond. These translation software tools include "compilers", "interpreters", and "development environments". The purpose of all of them is to allow you to work in a manner that is at least reasonably familiar, using simple operations such as picking items from a menu list, or giving written instructions in a language that looks no worse than a mixture of English and algebra. (Unlike English, with its 2,000,000 or so different words, a computer language typically has only about 100 words. So, many find learning a programming language far easier than learning a second human language.)

     In this project, you will learn to use one of these programming languages to construct, modify, and analyze a computer program for your own purposes. There are many such languages available, but the one most used in introductory programming experimentation is BASIC (standing for Beginner's All-purpose Symbolic Instruction Code). Although not containing many of the powerful capabilities developed by the software industry in the last 30 years, BASIC has a near-English appearance that is often appreciated by beginners. A very large number of books are available on BASIC, and on exploratory programming projects for beginners using BASIC.

     Note that there are slight differences between different company's implementations of BASIC (or any programming language), so consulting the manual for your specific language is sometimes pretty well mandatory. As there is no universally available, standardized, no-cost language at this time, you may need the help of your Project Leader or a friend in determining exactly what to do to fix a specific problem on the model of computer you're using, with the specific vendor and version of the programming language you're using. In practice, there's a good deal of similarity, but not exactness, so many people may be able to help you even though they haven't used exactly your set-up before.

     Unfortunately, with the release of Windows-95, BASIC is no longer a pre-installed, no-cost part of the Microsoft operating system software package. Other operating systems (e.g., Macintosh) may or may not include BASIC. So, whatever programming language you want to use, you or a helper may have to legally obtain a copy and install it on your computer in order to do this project. If you don't want to use BASIC, other widely available, reasonably priced (or sometimes even free), extensively documented, "beginner-friendly" languages include PASCAL and JAVA.


Materials Needed

     A compiler, or interpreter, or a "development environment" for the programming language you choose.

     Reference manuals on the programming language or environment.

     Books on sample programs for beginners with your programming language.

     Frequent access to the computer where you will be doing your programming.

     A printer connected to this computer (directly or via network) is very helpful.


Do It

     If you are using a development environment for windowing systems (e.g., Mac-OS, Microsoft Windows), you will need to read the material concerning how to send output to the screen and how to accept input from things such as text-entry boxes (i.e., the rectangles on the screen at which you're allowed to type things in) and pushbuttons. Although these instructions may appear as several lines of strange stuff, you probably can find an example program in the early part of the book that shows exactly what to type in to create a small program that does these things. You can follow suit from that, hopefully!

     Eventually, you'll be able to construct programs that are much easier to use and interact with, and that produce a much nicer form of output to the user. However, there's much more to learn in order to make the windowing system itself work, so you might want to start your programming experimentation using only the typed-in interface that doesn't have all the attractive graphics. For example, to read a number from the keyboard using BASIC, a command such as "READ X" is all you need, and that's pretty easy to understand.

Creating Your First Program

     Almost every programming language book ever written first shows you how to write an extremely simple program, often entitled "hello world". The program just prints something really easy, such as the words "hello" and "world", and then quits. But, by creating and running that program you will have proved: you know where the "editor" section of your programming language is, and how to type in a program, you know how to tell a program to run, and whoever did it, the installation of your programming language was done correctly, and the computer is able to find all the various parts it needs in order to run programs. So, it's important to take the time to find the instructions on how to create this first program, and to go ahead and do it. If it won't run, get help now, while your system is still in its simplest form.

In BASIC, all you need to enter for a "hello world" program is something like:

10 PRINT "Hello, world!"
20 END
RUN

     The steps are done in numerical order, once you type in the command "run". After your "hello world" program runs, you can have fun with variations such as a "hello Fred" program, or a program that prints:

Hello, world!
It's a beautiful day in the neighborhood!

     Your textbooks or manuals may have lots of simple programs you can easily type in and experiment with.

     Note that the exact way an instruction must be typed is termed its "syntax". So a "syntax error" means you either spelled something wrong, or used a comma instead of a period, or some other simple mistake.

Exploring the most important types of programming directives:

For the beginner level:  All programming languages have commands to do these things:

     Assignment of a value, usually the result of some calculation, to a variable. In BASIC, the syntax of an assignment statement for a numeric variable (one that contains a number) is:

10 A = B+3

     Note that "10" is only the line number (not required with all BASICs), and that the statement itself puts a number into A that is the result of getting the number in B and adding 3 to it.

     Input and Output to communicate with the human user. (Note that input means going in to the computer, and output means coming out of the computer.) In order to do most forms of really useful work, a program needs to be able to have you tell it what input data is to be processed. And, once the processing is done, there has to be a way to tell you what the answers are. Otherwise it's not much use! Combining both of these, plus the assignment statement, we have a BASIC program that reads two numbers and prints out their total:

10 INPUT A
20 INPUT B
30 T = B + A
40 PRINT T
50 END

     Comments to include notes to yourself (or others) concerning what you're doing and why. This gets to be really important in long programs where it's easy to get confused. It's also really important if you write a really useful program, such as a multi-function calculator, and decide you want to make changes to it a few years later on. The computer ignores these. To the program above, we might add the BASIC comment:

35 REM - I wrote this because I lost my calculator and I have math homework tonight.

     Conditional branching to allow the program to take different actions depending on conditions it encounters while it is running. For example, to modify the above program to continue accepting numbers and adding them until the user says something other than "y" for yes, add the BASIC lines:

45 PRINT "CONTINUE (Y or N)"
46 INPUT A$
47 IF A$="Y" OR A$="y" THEN GOTO 10

     Work with your Project Leader to examine and try sample programs from books that use these kinds of statements. Then, identify a very clear programming project with your Project Leader that will involve at least one of each of these kinds of statements. Generally, this project should not be taken directly from a book. To be entered in competition, this project must not be taken or lightly adapted from a book and must be the member's own work.

     Note that the State Fair terms programming projects at the Beginner level as "Category TBD". Contest nomenclature at county and regional fairs may differ. A member should only enter a contest in the Beginner Programming category once.

For the intermediate level:  You need to be completely familiar with all the types of commands in the beginner level. In addition, other types of commands have been created in all languages for the purpose of allowing people to understand what they are doing when they build larger, more complex programs. These commands include:

     Iteration or looping - additional commands to control repeating steps multiple times, particularly in situations in which large groups of numbers or records must be processed the same. If the number of repetitions needed is known in advance, a BASIC "FOR" loop is useful, as in this example that adds all the numbers from 1 to 1000:

10 T=0
20 FOR I= 1 TO 1000
30 T = T + I
40 NEXT I
50 PRINT T
60 END

     Other forms of loops repeat processing "until" a condition is true (e.g., until the last pay stub has been processed) or "while" a condition is true (e.g., a cruise control accelerating while the vehicle speed is in the "too slow" category). Selection between these alternative forms is usually on the basis of what fits the real-world problem description the best.

     Function calls - Complex calculations that are repeated at many points in a program often are best handled as "programmer-defined functions". These behave like the built-in functions to do common mathematical operations such as sine, cosine, square root, etc., but they may be any function you wish. For example, if a program of yours that is investigating engine fuel economy is repeatedly using the calculation 2.1*X**3 - 4.06 *X**2 + 11.9*X - 1.15, a helpful shortcut is to define the BASIC function:

DEF FNA(X) = 2.1*X**3 - 4.06*X**2 + 11.9*X - 1.15

and then to simply use that function like this:

W = FNA(1.25)
Y = FNA(-1.88)
Z = FNA(2.492)

rather than typing:

W = 2.1*1.25**3 - 4.06*1.25**2 + 11.9*1.25 - 1.15
Y = 2.1*(-1.88)**3 - 4.06*(-1.88)**2 + 11.9*(-1.88) - 1.15
Z = 2.1*2.492**3 - 4.06*2.492**2 + 11.9*2.492 - 1.15

     Procedure calls - Lengthy operation sequences that are performed from many points in a program, typically on different target data each time, are often best packaged into procedures that can be activated ("called") with different starting data. Procedures are similar to functions in that they do things you want; but, unlike functions, they don't return a value. The procedures generally do a task or set of tasks themselves, such as opening an output file or printing a paycheck, and there is no particular value to return. Note that some programming languages do not make much distinction between procedures and functions.

     Projects at the intermediate level should use more advanced programming constructs such as these, as the construct aids in the construction of the program. That is, these new command types need not be used only for their own sake, but should be used wherever they make creating the program easier. Projects at the intermediate level should never be close derivatives of material from a book, even if they are not being entered in a contest.


Review It

  • Discuss adding functionality/features and how to make said modifications.


  • Critique the program's usability. Have other people try it.

Pursue It

     Expand the scope of the undertaking, in a direction you like.

     Link with other program packages, e.g., get data from a database, not from type-in.

     Get real users doing real work with something you write (e.g., an appointment calendar program) and see what that's like.


Data Bank

     For more information see http://www.yahoo.com/Computers_and_Internet/Programming_Languages.



Activity: Write a computer program
Skill level: Advanced
Project skill: Writing programs
Life skill: Learnign to learn/problem solving
Date completed:

Helper's initials:


Adapted from material developed by Illinois 4-H. Used by permission.

For IFAS-related questions or information, please contact IFAS External Relations.
Copyright © 1994-2000 | University of Florida | Institute of Food and Agricultural Sciences | Gainesville, FL 32611
For Web site problems or suggestions, contact the site Web Master.