Beginning Programming All-in-One For Dummies. Wallace Wang
tasks, such as always displaying program commands in uppercase letters. If the editor doesn’t offer a feature you want or need, its macro language lets you add that feature. Without a macro language, an editor won’t give you the flexibility to work the way you want.
Project management helps you keep your source code files organized. Most programs no longer consist of a single file but of multiple files. Trying to keep track of which files belong to which project can be confusing, so an editor can help you store and organize your files so you won’t lose track of them.
Integrated development environments
An IDE combines an editor with a compiler in a single program so you can easily edit a program and compile it right away. It gives you access to these features within a consistent user interface (UI), as shown in Figure 4-5.
FIGURE 4-5: An IDE provides access to multiple programming tools within a single UI.
If you mostly write programs in a single programming language, using an IDE can be more convenient than a stand-alone editor.
Features
In addition to a compiler and all the usual features of stand-alone editors (see the “Common editor features” sidebar), many IDEs include other features in a convenient UI:
A debugger helps identify problems in your program.
File management helps organize the source code for your various projects.
A profiler helps identify which parts of your program may be slowing down the performance of your entire program.
A graphical user interface (GUI) designer helps you design the appearance of your program’s windows, drop-down lists, and buttons.
Free software
Many compilers come with their own IDE, but you can always use another IDE or a stand-alone editor instead. These IDEs are popular (and free):
Apache NetBeans (https://netbeans.apache.org
): Designed for writing Java programs, it can be used for writing C and C++ programs as well. NetBeans is available for multiple operating systems.
Atom (https://atom.io
): Atom is an open-source editor for Linux, macOS, and Windows.
Eclipse (www.eclipse.org
): Designed for writing Java programs, it can also be used for writing C, C++, PHP, and even COBOL programs. Eclipse is available for multiple operating systems.
Fixing a Program with a Debugger
Eventually, everyone makes a mistake writing a program. That mistake could be as simple as incorrectly typing a command or forgetting a closing parenthesis, or it could be as complicated as an algorithm that works perfectly except when receiving certain data. Because writing error-free programs is nearly impossible, most programmers use a special tool called a debugger.
Program errors are called bugs, so a debugger helps you find and eliminate bugs in your program.
Two common debugger features include
Stepping or tracing
Variable watching
Not all bugs are created equal:
Some bugs are just annoying, such as the wrong color on a drop-down list.
Some bugs are critical, such as a bug that adds two numbers wrong in an accounting program.
Any bug that keeps a program from running correctly is a showstopper.
Stepping line-by-line
Stepping or tracing lets you run your program line-by-line, so you can see exactly what the program is doing at any given time. The second you see your program doing something wrong, you also see the exact command in your program that caused that problem. Then you can fix the problem, as shown in Figure 4-6.
FIGURE 4-6: Stepping through a program, line-by-line, can help you find errors or bugs in your program.
Sometimes when programmers find one error and fix it, their fix accidentally creates another error in the program.
Here are the two types of debuggers:
Source level: Lets you examine your source code line-by-line. So if you write a program in C++, a source-level debugger shows you each line of your entire C++ program.
Machine language: Lets you examine the machine language code, line-by-line, that your compiler created from your source code. Programmers often use machine-language debuggers to examine programs when they don’t have access to the source code, such as a computer virus or a rival’s program.
Stepping line-by-line through a small program may be feasible, but in a large program that consists of a million lines of code, stepping line-by-line would take far too long. So, to make stepping easier, most debuggers include breakpoints and stepping over/stepping out commands.
Breakpoints
A breakpoint lets you skip over the parts of your program that you already know work. So, if you have a program that’s 10,000 lines long and you know the problem is somewhere in the last 1,000 lines of code, there’s no point in stepping through those first 9,000 lines of code.
A breakpoint lets you tell the computer, “Skip from the beginning of the program to the breakpoint, and then step through the rest of the program line-by-line.” Figure 4-7 shows how you can highlight a line with a breakpoint. That way your program runs from the beginning to the first breakpoint. After your program stops at a breakpoint, you can step through the rest of your program line-by-line.
FIGURE 4-7: Breakpoints let you skip over parts of your program that you don’t want to examine line-by-line.
Over and out
The stepping over and stepping out commands are used to debug a large program that consists of multiple