Table of Contents
Welcome back to our Intro to Programming article series!
In this article, I'm going to talk briefly about what programming is and the various steps that it usually involves. Don't worry too much if you don't understand some of the details, as you will revisit each of these in more details throughout the article series. In practical terms, programming is the practice of writing computer code to solve problems. Programming is a process that generally has several parts to it.
I want to emphasize even at this early stage that computer code is almost like a living thing that it is never actually finished - and never quite done changing or evolving. It evolves with the business or the problem it aims to solve. Similar to living things, it sometimes falls sick (catches "bugs") and requires medication ("bug fixes"). It also needs to be maintained in order to continue to function properly. As such, the steps we will outline below are often times repeated.
How Programmers Use a Problem Statement to Write Code
I'll begin with the problem statement. This is the phase where programmers will define the problem they are aiming to solve and understand the desired inputs and outputs of the program. For example, if the problem is "build a calculator," in this phase, a programmer will ask a number of clarifying questions, such as:
- What kind of operations should the calculator handle?
- Is the calculator only addition and subtraction, or does it handle multiplication, division, and taking the square root?
- Should the calculator only work with whole numbers as inputs or should it handle fractions also?
- How should the calculator handle wrong input? (For example, if the user asks the result of 2 + "what's for breakfast?").
- Should the calculator output only the result or should it output the mathematical notation, so something like 2 + 2 = 4?
- How should the calculator handle unexpected errors? (trust me, these happen quite frequently and need to be addressed)
It is important that the scope of the problem is clearly understood by all parties, otherwise unpleasant surprises may arise.
Why Programmers Design Solutions Before Writing Code
The second phase of programming is a phase of design. Here the programmers will spend time analyzing multiple possible solutions. For easier tasks, this can be done mentally, but for more complex problems, programmers will always use old-fashioned tools like pen, paper or a white board.
The purpose of this phase is to think through possible solutions for the given problem before investing a lot of time into writing code. As you'll learn, writing code is an expensive task, and the more you can do upfront to minimize code that you'll have to write or throw away, the better.
The design phase for complex problems often exposes trade-offs that can be made to achieve better performance or lower costs, therefore this phase, like the problem statement phase, often involves members of the team who are not programmers who are familiar with the business.
How the Process of Writing Computer Code Works
The third phase involves the actual writing of the computer code. In this article series, I will focus heavily on giving you the skills required to write computer code, however, I will also focus on design and problem statement where necessary. Writing the computer code is, perhaps surprisingly, not always the most time-consuming phase. As you gain more experience, the process of learning how to program will sharpen your mental capabilities and you will start to see the patterns much faster.
Sometimes, the part that takes the longest is the next phase: testing and debugging.
Why Testing and Debugging is the Longest Part of the Programming Process
Testing is probably the most obvious next step. You need to make sure that the computer code you wrote meets the specifications we agreed on, that it solves the problem you clarified during the problem statement phase and handles the agreed-upon inputs and outputs.
Testing simple programs is generally a fairly easy task. Testing programs that have complex dependencies can easily become a fairly involved task, and some companies have entire teams dedicated to testing alone. Still, as a computer programmer, you'll always have to do some testing yourself, but this task should not daunt you. With more experience writing code, you will become better and faster at programming and at testing too.
Image Source: 99 little bugs in the code, imgur.com
Part of testing is debugging. You may have heard this term and it has an interesting historical origin.
Computers in the early days were, as you probably know, massive machines that occupied whole rooms. They also often stopped working (the modern technical term is crashed) and sometimes that happened due to literal bugs or other insects that would get lost inside the computers and mess up with the circuitry.
The process of finding said bugs and manually removing them (and thus resuming normal operation of computers) came to be known as de-bugging. Today you (hopefully) no longer have to deal with physical bugs inside our machines, however the term still applies to the practice of identifying the cause of issues with our computer code.
So, coming back to our calculator example, if you wrote the code for it and asked it to calculate 2+2, and it outputs 5, the process of finding out why that happens is the process of debugging. You have several tools for doing this and I'll cover them throughout the article series.
How to Access and Deploy Your Written Code
Once the computer code is written and tested, the next phase is that of deployment. The process of deployment involves packaging your code and distributing it to a remote location (a server etc.) where users can access it.
In larger companies, often times specialized teams handle the deployment phase because programmers may not have access to critical infrastructure for security reasons. Smaller companies are generally different in that they don't have the means to afford a dedicated deployment or infrastructure team, so programmers will usually deploy their own code.
Deployment involves knowledge of particular infrastructures which are beyond the scope of this article series. However, I want you to be familiar with the term, as you will often hear it.
The phases I discussed are often repeated several times, as new requirements are added to the initial problem, or as new bugs surface while the code is being used by other people. This is why, it is generally a very good idea to take your time and think through your solutions thoroughly: it will save you a lot of time in the long run.
In this article, I talked about what programming is and what its various phases are. Thank you for reading! In my next article we will begin our exploration of the Python programming language.