Hello and welcome
Thanks for stopping by again.
Table of Content
Full table of content for the entire series is here
Today, we will address the following
-
Getting started (cont'd)
- Learn Programming concepts
Programming Concepts
These are the building blocks of the trade. We have touched on some of them during the introduction and definitions phase but here, we will take on the ones that you will need and use on a day-to-day basis as a developer. This is the foundation of your journey and if you get it right here, building on top of it will be a breeze 😜
There are quite a few concepts you will come across in your software development journey and anyone who tells you that they can teach you all of them in one sitting is probably trying to sell you something 😈.
Instead, we will go through the fundamentals, the basics, the ones you cannot escape and must know very well in order to be a decent developer. They are as follows:
- Syntax
- Algorithm
- Pseudocode
- IDE (Integrated Development Environment)
- Variables
- Data types
- Operators
- Control Structures
- If/Else Statements
- Loops
- Functions
- Input/Output (I/O)
- Data structures
- Arrays and Lists
- Objects and Maps
- Sets
- Stacks
- Queues
- Bugs and Debugging
- Functional Programming
- Object-Oriented Programming (OOP)
If we missed anything in the list above, please mention it in the comments and an edit might be on the cards. Also, we will need to split the explanations into 2 many sessions so this is part 1 of 2 n
where n
is some number we will determine at the end of this section.
Let us begin
Syntax
Simply put, syntax is programming grammar. The way we have grammar in any language which determines the correct order and arrangement of words and punctuations to convey what you want to say to a person, is the same way there is syntax defining the correct order and arrangement of what you want to ‘say’ to the computer.
Remember that programming is just you, giving the computer instructions, ‘saying’ stuff to the computer, telling it what to do.
For example: if you want to tell a friend to open your bag, bring out your book, place it on the table and open it, there is a proper sequence to doing this, a set of rules to follow and it might look something like this:
- Hi Najeebah
- Please open my bag
- Bring out my book
- Place it on the table
- Open it
You will not for example start the conversation with ‘place it on the table’ because then Najeebah will probably ask, place what on the table. Syntax error.
You will also not say ‘place the on it table’ or ‘plcae teh on it tblae’ because well that does not make sense and Najeebah will not know what you intend by that. Plus, it is weird to talk that way.
Syntax error.
This is in English and if you were speaking French or Arabic, you will naturally have to adjust to the syntax or grammar of these languages as well. The same applies in code. Each programming language has its own syntax and depending on the language you are speaking (writing your code in), you will need to adjust syntax.
The way you give each command in your code must align with the syntax of the language you are speaking to the computer, just like with human language.
Algorithm
This is the recipe for the task you are looking to do. It is a set of well-defined steps or instructions designed to solve a specific problem or accomplish a particular task.
A good algorithm needs to be at least all the following and maybe more:
- Clearly defined and easy to follow
- Take zero or more inputs and generate some output or result
- Must finish executing at some point (what is the point of a never-ending algorithm if we will never get the result from it)
- Must be consistent and predictable in its behaviour
- Must be a sequence of steps
There are many ways to represent algorithms such as natural/human language descriptions, pseudocode, flowcharts, or programming code. For now, we will use regular human language
Here is an example of an algorithm that adds two numbers:
1- Take input 1
2- Take input 2
3- Add input 1 and input 2
4- Store result in output
5- Return output
In the above algorithm, we see that there is a clear list of steps, inputs and outputs, it is finite in its execution and every time you run this 'function', the behavior and output can be predicted.
Now let us take a slightly more complex example that builds on the addition example above.
A calculator with the 4 basic operations (Add, Subtract, Multiply, Divide)
Before we do this, we should go back to what we learnt about problem solving and how we need to understand the problem and break it down before we execute.
The problem is to take 2 numbers and an operation and then execute the selected operation on the 2 numbers.
We need to handle all the 4 possible operations. We have an example of one operation above, so we just need to use some sort of decision system to decide what to do in case of each operation
Algorithm:
1- Take input 1 (First number)
2- Take input 2 (Second number)
3- Take input 3 (Operation)
4- If Operation is ‘Add’
5- Add input 1 and input 2
6- Store result in output
7- Return output
8- Else if Operation is ‘Subtract’
9- Subtract input 1 and input 2
10- Store result in output
11- Return output
12- Else if Operation is ‘Multiply’
13- Multiply input 1 and input 2
14- Store result in output
15- Return output
16- Else if Operation is ‘Divide’
17- Divide input 1 and input 2
18- Store result in output
19- Return output
You will notice that the steps in italics are checks to see if the operation input matches a condition and the steps in bold are the ones handling the actual computation depending on which operation was provided as input 3. We will get more into these concepts as we go further but the above is hopefully clear enough.
From these two examples, we can see that algorithms are nothing to be afraid of, just a step by step list of what to tell the computer to do with your code when you eventually write it.
Algorithms come before coding because with algorithms, you can lay out the steps to solve the problem without worrying about syntax since it is in human readable format
After some time, when you get really good in programming, it will no longer be necessary to write out the algorithms for simple tasks like addition or a basic calculator but for more complex tasks, it will always come in handy.
Pseudocode
It is one of the ways of representing algorithms and it is very similar to human language but unlike what we did above with human language algorithms, pseudocode has some code-like syntax. As the name ‘pseudo’ suggests, it is not actual code but resembles it.
For example, the pseudocode for our addition function from above will look something like:
function addition():
display "Enter the first number:"
read firstNumber
display "Enter the second number:"
read secondNumber
sum = firstNumber + secondNumber
display "The sum is: " + sum
In this pseudocode, the program prompts the user to enter the first number and the second number. It then calculates the sum by adding the two numbers together and stores the result in the variable ‘sum’. Finally, it displays the sum to the user as an output.
Remember, pseudocode is not tied to any specific programming language syntax, so you would need to translate this pseudocode into the syntax of the programming language you are using to implement the addition functionality.
It looks a lot like code, it is structured like code, we even gave it a black background like code, but it is not code 😜, still human language but written as Pseudocode.
IDE (Integrated Development Environment)
This is a fancy name for the text editor where you will write your code.
If you want to write an article for people who want to get started in software development like yours truly 😉, any text editor can do the job. Notepad, WordPad, sticky notes, TextEdit (on mac) and others will take in your text and allow you edit it and save but you will agree that none of these options is as productive as using Microsoft word or Google docs to write the article. Why is that? Well, because Word and Docs are designed for that specific task.
When you make a grammar (or syntax) mistake, Word will notify you with the red or blue underline, there are options to manage fonts, spacing, alignment, layouts and so much more right from the apps without much effort.
This is the same idea with IDEs, they are text editors designed to help you with code highlighting, code completion, syntax checking, indentation and so on. Some even help you build, run and deploy your code right from the IDE. It is true to say you can use other text editors like Microsoft word and Notepad for coding for sure, and the code will work if saved in the right format and run in the right way but an IDE is designed to help you with your code and is the right way to go just like with writing articles with Microsoft Word and not notepad.
Some IDEs are dynamic and can be used for several programming languages and some others are built specifically for specific languages. When we get to the coding part of this journey, we will be using VS code (Visual studio code) as our IDE
Variables
These are storage boxes for storing data values in the computer memory. Any task a computer does is largely dependent on data and involves data processing and manipulation. A variable is used to store and manipulate data in a program. It typically has a name and can be assigned a value when it is created. The variable name is like a label on the storage box of the data and the value may or may not change during the execution of the program.
A variable is created using a declaration or keyword that varies across languages. The declaration of a variable typically provides some information and context as to what data type is stored in it and how it can be accessed and manipulated across the application.
Variable names are typically alphanumeric, meaning they contain a-z and 0-9 and some special characters like underscore or the dollar sign.
It is also very important to note that the name you choose for a variable must be descriptive of what that variable is used for. If the variable is ‘user name’, calling it ‘var1’ or ‘un’ or ‘usern’ or ‘uname’ is not the best, and can be misleading for other developers and even you if you return to it after some time. Call it ‘userName’ so everyone knows what it is. The compiler might not complain about bad naming but it is bad nonetheless.
In the example of the pseudocode above, ‘firstNumber’, ‘secondNumber’ and ‘sum’ are examples of variables named properly.
Data types
Profoundly enough, this simply refers to the types of data. A little on the nose I know but that’s just how it is.
The most common ones (especially in JavaScript) are as follows:
- String: used to represent a ‘string’ of characters like a company’s name, a car’s plate number, a story, a phone number and the likes
- Boolean (true or false): used to represent a Yes or No situation and can only be either ‘true’ or ‘false’. No grey areas, it either is or isn’t
- Number: used to represent integers like 1, 50, 994 and floating-point numbers (decimal-base) like 75.2222, 3.14142142142, 322.435 and so on
- Array: used to represent a collection or list of data like the grade of everyone in a class or the salary of all employees in HR department
You may be thinking this surely will not be enough to represent every possible data in the world, like if you wanted to represent a person or a house or a fish as data in an application, you will need something more complex than these.
If you are thinking that then you are right, there are more complex data types. These here are the basics, and the more complex types can be created using the basics as building blocks.
Some programming languages have some more complex data types inbuilt and many of the mainstream programming languages allow you to build your own data types using other methods like object-oriented programming (OOP) which we will get into later.
We will stop here for this session so we are not overwhelmed.
The remaining concepts will be explained in the next one.
Until then, stay frosty and remember. We are here to help
Previous post is here
Next post is here
Top comments (1)
Superb as always.
Thank you for {in DJ Khalid's voice} another one!
Looking forward to the next episode.