FUNDAMENTOS
What is a program: the first article of the series, revisited
In 2017 I opened an intro-to-programming series with the most basic question: what is a program? Revisiting the text, with the credit that was missing and what I would add today.
In May 2017 I started an intro-to-programming series here. The first article answered the most basic question of all: what is a program?
The answer I gave was this:
A program is a sequence of instructions that specifies how to perform a computation.
That computation can be mathematical, like solving a system of equations or finding the roots of a polynomial. It can be an operation on text, like searching for and replacing words in a document. Or it can be graphical, like processing an image or playing a video.
Rereading it, a credit is missing: this definition and the list below are practically the ones in the first chapter of Allen Downey’s book Think Python. It’s still a good place to start.
The instructions that show up in almost every language
The details change from one language to another, but a few basic instructions show up in almost all of them:
- Input: get data from the keyboard, a file, the network or some other device.
- Output: display data on the screen, save it to a file, send it over the network.
- Math: perform basic operations like addition and multiplication.
- Conditional execution: check whether a condition is true and run the appropriate code for each case.
- Repetition: perform some action several times, usually with some variation.
It looks like very little, and that’s the point. Every program, from the simplest to the most complicated, is made of these pieces combined. In Python, a program that uses all five fits in a few lines:
numbers = input("Type numbers separated by spaces: ") # input
total = 0
for n in numbers.split(): # repetition
value = int(n)
if value > 0: # conditional execution
total = total + value # math
print("Sum of the positives:", total) # output
Why it’s worth learning, even if you don’t want to be a programmer
In 2017 I wrote for people starting out in IT who didn’t like programming. My view was that any area of IT calls for some programming foundation, just as people who like programming need to understand a bit of architecture and networking. Back then this was already part of the DevOps conversation, and it still holds today.
It doesn’t have to be for building large systems. A small script that renames files or merges reports already saves a lot of repetitive work.
What came next
The article ended by announcing the next one in the series: the algorithm, which is what gives meaning to the sequence of instructions. It came out in September 2017, in #2 - What is an algorithm?.
Who writes this
Eduardo Lira
Software developer in Rio de Janeiro. I started this blog in 2012, in technical support at a hosting company, writing down the fixes for the problems that came up every day. Today I work at Sofis Tecnologia, on critical healthcare systems and SQL Server database migrations.