An Overview of Linux Programming
Linux comes loaded with all the tools you need to develop software. (All you have to do is install them.) In particular, it has all the GNU software-development tools, such as GCC (C and C++ compiler), GNU make, and the GNU debugger.
If you have already taken a look at some simple tools and shell scripts, here take a look at programming, the software-development tools, and some simple ways to use them.
Although you can find examples in the C and C++ programming languages, don’t focus on learning how to program in those languages, but on showing you how to use various software-development tools (such as compilers, make, and debugger).
Don’t forget to look into how the Free Software Foundation’s GNU General Public License (GPL) may affect any plans you might have to develop Linux software. You need to know about the GPL because you use GNU tools and GNU libraries to develop software in Linux.
If you’ve written computer programs in any programming language, even simple shell scripts, you can start writing programs on your Linux system quickly.
If you’ve never written a computer program, however, you need two basic resources before you begin to write code: a look at the basics of programming and a quick review of computers and their major parts.
At its simplest, a computer program is a sequence of instructions for performing a specific task, such as adding two numbers or searching for some text in a file. Consequently, computer programming involves creating that list of instructions, telling the computer how to complete a specific task.
The exact instructions depend on the programming language that you use. For most programming languages, you have to go through the following steps to create a computer program:
Use a text editor to type the sequence of commands from the programming language.
This sequence of commands accomplishes your task. This human-readable version of the program is called the source file or source code. You can create the source file with any application (such as a word processor) that can save a document in plain-text form.
Always save your source code as plain text. (The filename depends on the type of programming language.) Word processors can sometimes put extra instructions in their documents that tell the computer to display the text in a particular font or other format. Saving the file as plain text deletes any and all such extra instructions. Trust me, your program is much better off without such stuff.
Use a compiler program to convert that text file — the source code — from human-readable form into machine-readable object code.
Typically, this step also combines several object code files into a single machine-readable computer program, something that the computer can run.
Use a special program called a debugger to track down any errors and find which lines in the source file might have caused the errors.
Go back to Step 1 and use the text editor to correct the errors, and repeat the rest of the steps.
These steps are referred to as the edit-compile-debug cycle of programming because most programmers have to repeat this sequence several times before a program works correctly.
In addition to knowing the basic programming steps, you also need to be familiar with the following terms and concepts:
Variables are used to store different types of data. You can think of each variable as being a placeholder for data — kind of like a mailbox, with a name and room to store data. The content of the variable is its value.
Expressions combine variables by using operators. One expression may add several variables; another may extract a part of a string (series of sequential characters).
Statements perform some action, such as assigning a value to a variable or printing a string.
Flow-control statements allow statements to execute in various orders, depending on the value of some expression. Typically, flow-control statements include for, do-while, while, and if-then-else statements.
Functions (also called subroutines or routines) allow you to group several statements and give the group a name. You can use functions to execute the same set of statements over and over by invoking the function that represents those statements. Typically, a programming language provides many predefined functions to perform tasks, such as opening (and reading from) a file.