How to Write a Program: Coding, Testing & Debugging

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: Object-Oriented Programming vs. Procedural Programming

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
 Replay
Your next lesson will play in 10 seconds
  • 0:05 Steps to Writing a Program
  • 0:39 Writing Code
  • 2:10 Syntax
  • 3:47 Testing
  • 5:12 Debugging
  • 7:03 Lesson Summary
Add to Add to Add to

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Login or Sign up

Timeline
Autoplay
Autoplay

Recommended Lessons and Courses for You

Lesson Transcript
Instructor: Paul Zandbergen

Paul has a PhD from the University of British Columbia and has taught Geographic Information Systems, statistics and computer programming for 15 years.

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:


Example of IDE
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:


Original code in plain text
before highlighting syntax


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


Same code in IDE
syntax highlighting


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.

Testing

Once you have written your code and checked for any syntax errors, you are ready to start testing. A program that is free of syntax errors will execute. However, this does not mean it actually works.

For example, let's say you have a file with the payroll information for each employee, with each employee represented by a line. You need a computer program that can read this information line by line and perform some type of payroll-related operation, such as calculating benefits for a certain pay period. The results should then be written down to a new file.

Before running the program on the actual payroll data for a real company, you want to do some testing. Testing consists of determining whether the program executes the tasks intended. Does the program do what it's supposed to do?

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 160 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create An Account
Support