Software Engineering/Coding: A Gentle Theoretical Introduction
Let’s face it, learning is hard! You have to go through extended periods of intense focus and training your brain not to wander around not to mention the bazillion errors and configurations during the practical sessions. Given all the noise around us in this age, that is like trying to cage a puppy. However, the best approach to learning anything new is starting with the basics, gently introducing new concepts referencing to what you already know, and brick by brick you gently add new knowledge to existing cognizance.
That is what this article is about. I will gently introduce you to coding in the easiest and most brain-friendly way — if there’s such a word. By the end of this article, my hope is that you’ll understand coding and the whole discipline of programming a lot better, positioning yourself for more advanced lessons. This article is not strictly theory, to have a solid understanding of the theoretical knowledge, we’ll have a simple practical session.
Motivation
I spoke to a few folks who took the ALX SE program, some completed the program, some didn’t and I wanted to know what their challenges were. This research was not limited to one program or a particular group of people. I conversed on the same with a few of my friends too on why they think coding or learning how to code is hard.
One problem that came out was, there are a lot of starting assumptions that most tutors seem to miss. Introduction to a new concept should be preceded with an assumption that the new knowledge will be built on an already established apprehension of the prerequisite knowledge for that new insight.
An example would be me telling my girlfriend, “For you to contribute to an open source project, you have to fork the repo then clone it locally…” That even for you reading this article with little to no IT knowledge is all gibberish!
Enough of that now let’s get down to why we’re here…
The Proposition
To start, let’s look at the definition of a computer. I like the definition I was taught in high school; a computer is any device that accepts inputs/instructions/commands, processes that input and transmits information/data/output back to the user. Information/data being processed instructions.
Ooookay, hold on a second, what did you just say?
To understand this let’s look at an example, you make a mobile-money transaction on your phone and you see that ‘transaction successful!’ pop-up, that’s basically it. You take your phone go to google and search software engineering and it gives you a whole bunch of links with that name, that’s what I’m talking about. You take a calculator, punch in 3+3 and it says 33, again that’s a computer. In simple terms, a computer is any electronic device that you tell it what to do it does that ‘something’ and then reports back with an answer/data/information. Given what I’ve just explained, here is a brain teaser — can the watch you’re wearing be considered a computer? Let me know in the comments.
Before we go any further, first let’s look at a concept. You see, computers are basically machines, I mean, it’s just a bunch of electrical components and electricity flowing through them. When you punch in 3+3 the computer/calculator doesn’t understand what you’re saying, remember the 1s and 0s you saw in The Matrix? That’s the language the computer understands, also called Binary/Machine code. Basically a 1 means true or on (electricity flows) and a 0 means false or off (electricity not flowing). Remember I mentioned that a computer is basically a bunch of electrical components transmitting electrical signals? So computers speak in 1s and 0s (either electricity if flowing or not), human beings use complex language systems, like English, Swahili, and German, which in most cases is comprised of complex alphabetical and numeral characters. How do we bridge the communication gap between these electrical components and human beings?
This is where a programming language comes in. A programming language is made up of two parts, the syntax that you have to learn-- print(“Goobye Mars”) — and what we call an interpreter or a compiler depending on the language.
Let’s look at an example
In this practical session, we’ll install python on our computer and write a very simple program. First things first, you have a computer and internet connection (covering the starting assumptions). Head over to python’s website. Look for the “Downloads” page then download ‘whatever they ask you to download’. Simply what we are doing is installing Python’s interpreter on our computer, I wrote this working on Windows operating System, if you’re using a different operating system, they should have the guide for installing python somewhere on the website.
After you download that package, go ahead and run it to install (double click or right click and select run). Use the default settings for now.
After you’re done installing, from your apps drawer (bottom left corner on your desktop), search for python and click on the python.exe icon.
The below terminal will open.
What did we just do? Basically what we just did, is we installed the python interpreter and now we’re ready to give the computer instructions using Python’s programming language syntax.
What’s an interpreter? The interpreter takes the instructions/code we type in, and converts it to binary language that the computer (a bunch of electrical components transmitting electrical signals to and fro) can understand. Now in the terminal that is open, go ahead and type in the first two lines below hitting enter after every line;
name = "Mbadi"
print(name)
This should be the output >>>Mbadi
We just issued a few instructions and the computer processed them. Our instructions were issued using alphabetical characters, but the interpreter we downloaded converted those commands and sent them as binary to the computer. The computer processed the instructions and then sends the answer/output in binary, the interpreter again, converted the binary answer into a language we humans can understand. That is what programming is all about.
Programming is not all about issuing simple instructions like I have explained. Thousands of instructions are packaged into what we call a program. A good example would be an app running on your phone, or a simple calculator program;
# This function adds two numbers
def add(x, y):
return x + y
# This function subtracts two numbers
def subtract(x, y):
return x - y
# This function multiplies two numbers
def multiply(x, y):
return x * y
# This function divides two numbers
def divide(x, y):
return x / y
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
while True:
# take input from the user
choice = input("Enter choice(1/2/3/4): ")
# check if choice is one of the four options
if choice in ('1', '2', '3', '4'):
try:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
except ValueError:
print("Invalid input. Please enter a number.")
continue
if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '2':
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == '3':
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '4':
print(num1, "/", num2, "=", divide(num1, num2))
# check if user wants another calculation
# break the while loop if answer is no
next_calculation = input("Let's do next calculation? (yes/no): ")
if next_calculation == "no":
break
else:
print("Invalid Input")
The above snippet is a simple calculator program written in python. In this case, you would use what we call a code editor like Notepad ++, Sublime text, Visual studio code, then save the file as something like calculator.py. You can then just run all the instructions as a package/program, but don’t worry about all that complexity for now.
Just like learning any other language, you have to learn the syntax of that specific programming language. In Kiswahili, for example, you have things like tanakali za sauti, vinyambulizi I don’t know what,….etc. Each programming language has its own different syntax, some relatively similar to each other and some very different.
Why have many languages? Well, each language is designed differently depending on how fast it is, the amount of space it occupies, ease of learning and things like that.
That’s it for this article folks. Keep studying, keep practicing. Let me know down in the comments if I missed or mislead you in any way or if you have anything you would like to add.