How to Write a Program: Coding, Testing & Debugging

Programmers use an integrated development environment for formatting code, checking syntax, and testing programs. Learn about some of the specific tools used by programmers, such as syntax highlighting, autocompletion, and debugging.

Steps to Writing a Program

The general steps for writing a program include the following:

  • Understand the problem you are trying to solve
  • Design a solution
  • Draw a flow chart
  • Write pseudo-code
  • Write code
  • Test and debug
  • Test with real-world users
  • Release program
  • Iterate the steps for the next version

This lesson will look more closely at writing code in programming language. Once code has been written, it has to be tested and debugged to make sure it works as intended.

Writing Code

Computer code is essentially a list of instructions that can be run by a certain program. Most code consists of plain-text documents so they can be used for many different programs. A unique file extension is given to the document to indicate the nature of the code. For example, a file created using Python is saved with a .py extension, like ‘myprogram.py.’ However, the actual content of the file is still just plain text.

Because most code is in plain text, you can write code using a basic word processor or text editor. However, it is much more effective to use a software application that is specifically designed for coding in a particular language. For example, when you write a document in plain English, you would use word processor software, which can assist you with things such as formatting, spelling, and grammar. Similarly, a code editor provides tools such as syntax checking. Syntax is to code what spelling and grammar are to writing English.

A code editor is also called an integrated development environment, or IDE. An IDE is a software application for formatting your code, checking syntax, as well as running and testing your code. Some IDEs can work with multiple programming languages, while some are very specific for only one language.

Here is an example of what a typical IDE looks like:

IDE example

This may look overwhelming, but you can think of this as a specialized word processor for programmers to write code.

Syntax

One very useful aspect of IDE is known as syntax highlighting. This means elements of the code are shown in different colors based on what they are. Let’s look at a very simple example. Here is the original code in plain text:

before highlighting syntax

Now let’s look at the code in an IDE:

The colors make it easier to recognize the various elements of the code. For example, in the sample code, the elements ‘for,’ ‘in,’ and ‘print’ are keywords that hold special meaning.

Syntax highlighting makes it easier to read code. However, it does not change the actual meaning of the code, and it is only for human readers.

An IDE includes tools for syntax checking, which is similar to checking grammar and spelling. If code contains syntax errors, the program will simply not execute. An IDE identifies exactly where the syntax errors are.

Most IDEs also have some form of autocompletion system built in. You may be familiar with this if you do any text messaging on a smartphone. As you start typing, the program will determine what it is you are trying to type. For example, if you type ‘pr,’ the IDE will suggest ‘print.’ Autocompletion in an IDE will typically provide a list of options to choose from, not just the most likely option. This saves on typing and also reduces typos. Autocompletion in a coding environment is also referred to as intelligent code completion.