A few weeks or maybe even more than two or three months ago I scribbled down on a piece of paper my understanding of the basic concepts in procedural or functional programming. I look it over from time to time just to re-enforce my understanding of it.
Today I decided it would be nice to share this on this blog. I am not saying it is a complete overview, nor that it is 100% correct. It’s just my current understanding of the matter so far.
When writing a program, or just a simple script we usually want to use and manipulate data. Therefore we will want to temporarily store that data so the script can access it easily. Data is temporarily stored in the following ways:
- Variables (for single values)
- Arrays, or lists (for multiple ordered values)
- Associative arrays, or dictionaries, or hash tables (for one or more key-value pairs)
Besides this, I know of concepts of sets and tuples, etc., but the above three are the most basic and are found in almost every program language I know (except for Bash, which does not have associative arrays).
When writing code it helps to group lines of code that do a specific thing. And then we usually want to be able to call this grouped code block and possibly feed in some data and receive an output. This grouping can be done in the following ways:
- Procedures, or functions
- Subroutines: side effects only; no in- or output
While we manipulate data we need to make decisions about what to do next; flow control if you will. To facilitate this, most languages have at least some of the following constructs of some form:
- if, else, then
- switch, case
Computers are really good at doing the same thing over and over again and doing it ever faster. This repetition is also known as looping or recursion. Most commonly I have seen:
- Recursion: calling itself
If you are familiar with object-orientated programming you might want to add the concepts of classes, methods, and inheritance to this overview although OOP is not functional. I currently understand the basics of OOP only.
I know that this might seem awfully basic and maybe cryptic, but I hope that if you know a little programming, that it makes sense and that it will give an overview of the concepts regardless of what language you favor.