Programming Paradigms | What Are They and How Do They Work?

(disclaimer: this is a beginner’s explanation and understanding of these programming paradigms. if there are any errors or confusion, please let me know and I will edit or correct those to become more understandable. this is intended to be a basic overview.)

In my quest of self taught programming, I figured I’ve reached the point of needing to really understand what an object is, as well as the difference between the big types of programming:

  • Object Oriented Programming (OOP)
  • Functional Programming (FP)
  • Structured Programming (SP)
  • Imperative Programming (IP)
  • Procedural Programming (PP)
  • Declarative Programming (DP)

How do these all relate? What are the pros and cons of using each one? I decided to go on a researching rampage.

Let’s clarify some terms. What is a paradigm?

  • n. A set of assumptions, concepts, values, and practices that constitutes a way of viewing reality for the community that shares them, especially in an intellectual discipline.
  • n. A system of assumptions, concepts, values, and practices that constitutes a way of viewing reality.
  • n. A conceptual framework—an established thought process.

So in our case, a paradigm is a way of looking at programming: understand the underlying framework of the language’s ideas that make it work the way it does and implementing programs through the filter of that structure.

As wikipedia says, “a programming paradigm is a way to classify a programming language based on the features it possesses.”, filtering the abilities through a set of ideas to classify it. Programming languages can share qualities/features that tie into multiple paradigms, so there isn’t one strict classification for each language.

“Some paradigms are concerned mainly with implications for the execution model of the language, such as allowing side effects, or whether the sequence of operations is defined by the execution model. Other paradigms are concerned mainly with the way that code is organized, such as grouping a code into units along with the state that is modified by the code. Yet others are concerned mainly with the style of syntax and grammar.” ~ wiki

Structured Programming

Structured programming focuses specifically on program organization. The programs are typically executed in the exact format it is laid out in, from beginning to end, using statements. There are four terms usually associated with structured programming:

Sequence: The order in which to execute the program, often a linear format of statements.

Selection: Based on the state of the program (local and global changes), statements are executed (Statements such as if/then/else/else-if).

Iteration: Iteration in the sense of SP has to do with a statement repeating or being executed until the desired program state is reached. (for/do, while, etc).

Recursion: The program repeatedly calls itself until the desired state of the program is reached or something external terminates it.

Structured programming can be implemented in any language. It is often used for small, clear programs like OS system interrupts or external interrupts.

Procedural Programming

Procedural programming is defined by a concept called “procedure calling”. This is similar to functions, but the term focuses on different features.

Procedures can be functions, routines, subroutines, and more. It’s an overarching term for “a thing that does a series of other little things, kept in a box that you can call and open, filter a thing through, then close and put away”.

Some programming languages classified as “procedural” are C, Fortran, Go, and BASIC. Hardware is designed to support these languages with the stack register(s) (a register that holds all the calls, pointers, and organizes the program) to make sure that things are called correctly, and return successfully before moving onto the next procedure.

Imperative Programming

Considering a language as imperative is classified as programming with statements to change the state of the program. It’s focus is to describe with the commands how the program works. It is concerned with the process of getting to the output, not necessarily the output itself.

The idea is similar to imperative statements in the English language: if you say something imperatively, it is a command, something that implies you want a thing done. Translating this to programmer terms, you’re literally commanding the computer to do things.

To quote wikipedia, “imperative programs consist of commands for the computer to perform”.

Imperative programming is linear, which means you tell the computer every. little. step. you. want. it. to. take, and that’s how it will be executed. You focus directly on how you’re instructing the computer to do things. Lower level code in C or Assembly is considered imperative programming.

Contrary to usage, procedural programming and imperative programming do not reference the same thing. While imperative programming focuses on how you’re telling the program what to do, the structure you’re writing it in, procedural programming is focused on the idea of calling those procedural “boxes” and executing them.
Procedural programming is a sub-classification of imperative programming, because you’ll likely use the imperative code to write the procedures you want to call. “[T]he use of procedures has a dramatic effect on how imperative programs appear and how they are constructed.” ~ wiki

Declarative Programming

Declarative programming is the opposite of imperative programming, it is defined as “anything not imperative”. The languages considered as so typically associate with mathematical logic, rather than explicitly listing the steps you want the computer to perform. The languages defined as declarative often have the ability to support no side effects (modifying things like variables outside of the function’s scope, which depends on program state).

Functional Programming

Functional programming is a sub-classification of declarative programming. It is a style of programming that “treats computation as the evaluation of mathematical functions (expressions) and avoids changing-state [side effects] and mutable data.” ~ wiki

Imagine we have function, and we passed it (x). Calling function twice with the same input value for (x) will result in the same return value of f(x)each time, as opposed to having the output possibly change depending on a program’s state (due to a local or global variable).

This makes it much much easier to predict the outcome or behavior of a program, because you have more clarity on the flow of the data, you know what to expect.

Functional programming is used in programs where you have a fixed set of data, but need to add new operations every once in a while to process it differently. Languages like Haskell, Common Lisp, Scheme, Clojure, and Erlang all support functional programming.

Functional programming has some powerful implementations, like pure functions and high order functions. I don’t understand them well enough to explain them here, so go and do some research for yourself!

Object Oriented Programming

Lets clarify what an object is: Objects are a thing that have a state and a behavior. If you take a look at literal objects around you:

My phone’s state’s can be On or Off, bright or dim, silent or ringing.
My phones behavior can increase volume, decrease volume, web surf, search, play music, pause music, send call, hang-up call (etc).

Lamp’s state: On, Off
Lamp’s behavior: turn on, turn off, (maybe even explode!)

State: mechanical (or wood), lead (vs ink), erase, don’t erase
Behavior: write, delete/erase, refill, click

An object in programming stores its states in fields (the storage of the data) and displays its behavior with methods or functions (the activity that will be performed on the data it receives).

Object Oriented programming focuses on data, where you have fixed methods/operations that you pass new data to. Programs with OOP are rooted in the creation and interaction of objects themselves as they sift through the ever-changing data passed to them.

Languages that support OOP or are designed specifically for OOP: Java, C++, C#, Python, PHP, Ruby, Perl, Swift, Dart, Scala, Common Lisp, and SmallTalk.

Objects are extremely useful if implemented correctly. You can imagine objects as the nuts and bolts that, when built, work together as a machine. If the machine breaks, you replace one part, not the whole machine.

Object oriented programming has one more term that is worth mentioning, called data-encapsulation. Think of objects like the human body and it’s makeup. There are all the internal organs inside, but we can’t access them unless we do specific things. Say we wanted to access the stomach, to do so, we would eat food. We inputted the food, it goes through the stomach, is processed, and I’m sure you can imagine what the output is.

Did we see on the inside everything that was happening to the food? Nope! We passed an argument, and got a value returned. Data encapsulation is the idea of hiding the state of the data until it is returned by the object.

I hope this was educational to you, as it was to me! Now I fully understand more what people mean when they reference these terms, and hopefully I can start implementing these ideas into my own programs.

If you have any questions, don’t hesitate to contact me and ask more. Corrections and clarifications are welcome!



Adventures in Common Lisp and Project Newton

Goooood morning!

In the last few days I have taken on the challenge of learning Python and Common Lisp at the same time. My experiences in programming have been little, only writing some small programs in Assembly or Forth here and there, so this has been a big jump for me.

I’m learning Python because my friend and I wanted to write a scratchpad bot for our discord server – a bot that will grab the last message (or however many messages you specify) and put that message in a JSON file for you to reference later. in UTW,  we share ideas, commands, programming techniques and more, so this is a very helpful tool. I’ll get a post up about him and the things I learned while designing him soon.

As for Common Lisp, I love lisp. It’s much less choppy than Python feels, and very intuitive to me. It’s similar to forth, in a way, but obviously more documented and widely used.

Documentation of things I have learned about Lisp:

Parentheses. Everywhere. It’s beautiful.

The function values() returns multiple values, not a list of values. It’ll return the actual values and won’t break your code if not all of them are used!

&optional is a keyword you can put into the arguments part of a function to tell the function that these arguments are optional. If no value is provided, you can set the argument to a default value:

(defun foo ($optional (bar "Hello World")) (print bar))

This creates a function foo that’ll take an optional argument bar. If you pass bar to the function, bar will become that value. If nothing is passed to foo, bar will print “Hello World”.

the function clear-input, as I understand it, cleans away any stray or unprocessed input, making sure it’s all inputted, before it starts executing the next code.

finish-output makes sure everything successfully printed to the output-stream and returned.

write-string is the same as write-line, except for write-line adds a newline before it prints.

parse-integer will take input and evaluate it as an integer, then return the value. Or throw an error if the input isn’t an integer.

I also learned about asdf systems, which are super useful! ASDF stands for Another System Definition Facility. It is for programmers and hackers to build and load software in Common Lisp. So all of your files that depend on each other (in a project, for example), you can load them in specific order dependencies based on a project-name.asd file and load it into SBCL to test and run things, working similar to how you would load a required package with quicklisp.

What is ASDF

Getting Started with ASDF

And with that, I can sort of announce the Lisp project I’m working on! It’s called Newton, which I started to help teach me lisp.
Newton is a Physics calculator, dictionary, concept-teacher, reference, you name it. Like a mini teach-yourself-phyics program! It’s been lots of fun so far, you can see my ASDF System file for Newton here:

The actual code is far from complete, I’m still extensively experimenting with the little bits of lisp that I know.

Until next time!


i3 Window Manager + Notification Daemon Dunst

I haven’t been doing a ton of super nerd things lately because of school and work, so I decided to play around with setting up the i3 window manager; one, because I wanted to learn a new way to navigate my computer, and two, because I’ve been bugged to try it one too many times. XD

So! I installed i3 with:

sudo apt-get install i3

Then restarted my computer. When logging back in, there should be a little gear icon that shows up right by the “login” button. Click on the gear and i3 should be an option to choose from.

A window should pop up asking what you want your $mod key to be. the $mod key is the key that will start all of your keybindings. i3 window manager is all about keybindings, so if you want a fun learning curve and hate using the mouse, this is the window manager for you!

At first I was terrified because I couldn’t figure out how to get a terminal set up. Then my friend advised the keybinding, $mod+enter. I had chosen the Win key as my $mod key, so it was win+enter. 🙂

Once I had my terminal up and running, I had to fix the scaling on my mac with its fancy HiDPI screen. But other than that, the next step was to jump into the config file. The config syntax wasn’t hard to learn, and you can find my config file here:

As long as you can get a terminal and start working with the config (in spacemacs, emacs, vim, nano, whatever!) you’re basically using i3, you just have to keep remembering the keybindings to get where you want to go.

Configuring all the colors is so much fun. I ended up making a keybinding cheat sheet while I’m in the works of getting them all memorized. img_5598

I’ve found so far that in some cases I like working in tiled setup (when working on coding projects) and fullscreen+tabbed in day-to-day usage. 🙂

If you have trouble maneuvering around and starting programs, I’d recommend installing rofi and binding it to a comfortable keybinding position (mine is Control+space). Rofi is like dmenu, but much prettier. It’ll pop up and allow you to execute programs like firefox, screenshot, and more, all without touching the mouse, which I appreciate.

I wasn’t fond of the notifications in i3, so I took to the interwebs and found Dunst. Dunst is a cool little notification daemon that you can use to replace the default i3 daemon, plus it’s configurable! *laughs maniacally*

You can get dunst by:

git clone
cd dunst
sudo make install

And that should be the end of that. I highly recommend installing all the dependencies before trying to make, or else you’ll get some nasty errors.

The next step is to switch the i3 notification daemon from the default to Dunst.
cd into /usr/share/dbus-1/services/, then find a file that looks similar to org.freedesktop.Notifications and sudo vim into it.

After Exec, replace Exec=/usr/lib/xfce4/notifyd/xfce4-notifyd with:

Save and quit!

Once completed, sudo mv /path/to/dunst/folder /usr/share/

Then copy over the config file:
sudo cp /usr/share/dunst/dunstrc /home/username/.config/dunst/dunstrc.

Now you can configure everything to your heart’s content! Here’s a good article to get you in on the basics, and here’s my dunst config file:

Happy configging!


Mock up PCB | binary watch

I soldered deep into the night….and all throughout today.
After hours of writing and testing code, fiddling with hardware, and scraping through error after error, I can present to you the first mock up through-hole PCB!

I designed the schematic on EasyEDA:


And followed the setup from there. I’ll redo the schematic on EagleCAD because I was using EasyEDA mainly for the learning experience of using a different software. I could stand to make it a bit easier to look at, too.

Getting all my tools and supplies out, I pumped this guy out after a few hours:


The connections on the back are a little gross, but I was excited to get it done! As you can see, I hadn’t had room to stick a coin cell battery holder, let alone the battery itself on the back, so made a smaller PCB that acted as the power source.This was slightly tricky, as I had to figure out what was GND and what was the power, and where I was supposed to connect all the wires to.





Once everything was Vcc’ed and GNDed, I plugged the microcontroller, shift registers, and battery in….img_5532.jpg

and boom!



The coin cell battery powered it quite well, and I believe once I start using the deep sleep modules, it’ll be even more efficient. I will have to test how much current the microcontrollers, shift registers, and LEDs are drawing to make sure, of course.
The wiring was a little iffy, if I shifted the wires by accident the program would restart. I wasn’t too worried about that, because it worked all at once the first time I plugged it in and didn’t touch it. A little wire debugging wouldn’t hurt in the future, but I’m happy for now.

I’m so proud of how far I’ve come and everything I’ve learned so far. There’s nothing like a project to teach you so many new things and hone your skills. Here’s to more advancements soon!

Again, you can find the ATmega pinouts and my circuit design in this blog post: Prepping the ATmega328P: bootloader burn, fuse-byte programming, and hardware test | binary watch, as well as have access to all my resources on my github repository.

Next steps will require making  a new schematic that’s easier to read, start working with the low power modules, and sketch out some experimental PCB design.


Prepping the ATmega328P: bootloader burn, fuse-byte programming, and hardware test | binary watch

Now that the basis code is all ready, it was time to test it out without help of the Arduino UNO, straight with the hardware of the ATmega328P.

After doing research, if you have a completely empty ATMega328P, you need to burn the bootloader, load the new code, and burn the fuse bytes to be clocked by an external clock (not to mention find a way how to burn the fuse bytes).

I didn’t know how to do any of this at first, but with careful research and reading of a lot of stackexchange forum posts and blog posts, I was able to complete these seemingly tough tasks.

Burning the bootloader is important if you want to program the ATMega328P through the ArduinoIDE, it allows the arduinoIDE to communicate to the microcontroller and write the code accurately to the memory.

There are multiple ways to go about burning the bootloader, but many of the suggested ways on the Arduino website failed to succeed with my ATMegas, so I resorted to a much easier setup, with optiLoader.

Following this documentation, I got the bootloader setup correctly.

You need an Arduino UNO, a 16MHz crystal, 2 22pF capacitors, and a 10K resistor. Some say you can do it with or without the 16MHz crystal and the capacitors, but mine wouldn’t work without them, so it’s a good idea to have some on hand in case you get the same errors I did.

First, create a directory in your Arduino folder, where all the sketches are usually kept. Name the directory optiLoader, and in that directory, use git to clone the repo into that folder:

git clone

after it clones, upload the .ino file to the UNO, then setup your breadboard.

The breadboard setup looks like this, adding the capacitors and 16MHz crystal needed:


Once done, double check your wires, I goofed up on one and it threw my circuit off. Double checking always pays off!

Plug the Arduino UNO into a power source, open the serial monitor at baud (19200), and you should see the output of success or failure!


Congrats, you just burned your bootloader.

Next step, burning the fuse bytes….but uh, what are those? How does that all work?

There are usually two or three fuse bytes in a microcontroller, and these fuse bytes are programmed to tell the microcontroller how to work, for example: which clock to use (external, internal, how fast/slow), how much memory to set aside for programs, the boot sequence, watchdog timer setup, etc.

They’re factory set when you buy them, so if you end up messing around with the circuit and find you need an external crystal like I did, you’re gonna need to reprogram the fuse bytes.
A counterintuitive part of this process is: a bit set to 0 means it is programmed, and a bit set to 1 is unprogrammed.

WARNING: if you do not do this correctly, you may end up with a microcontroller that does not work!

Still with me? Didn’t get scared? Great. Let’s move on!

I recommend pulling up the ATmega328P datasheet to follow along in this topic, you’ll need to scan through it as I go over things.

There are two fuse bytes we’ll be working with. The High fuse byte and the Low fuse byte. There are 8 bits within each, and they all stand for a different setting.


This is the HIGH fuse byte, 0b11011001. As you can see, certain 1s are unprogrammed and the 0s are programmed.

The fuse byte that we’ll be toying with is the LOW fuse byte:


In a very helpful article, they mentioned that you do not want CKDIV to be programmed if you’re adding a crystal, so I automatically know that’s 1. We’re going to leave CKOUT, and move on to finding SUT1, SUT0, and CKSEL3..0.


In the chart above, we see that there are multiple different clocks you can program the ATmega328P to choose from. In our case, we want the Low Power Crystal Oscillator, which, on the side, means that based on how we configure it, the nybble of CKSEL could be anywhere from 1111 to 1000. That gives us a good approximation, and helps us move onto the next chart:screenshot

Here, this chart tells us what CKSEL will be based on the MHz value of our crystal. I’m using a 16MHz, so CKSEL[3:1] is going to be 111. That also means I’ll use two 22pF capacitors.

Alright, so we have the first part of our LOW byte, now we need to figure out what CKSEL0 and SUT[1:0] are.


Woot woot! Final chart!
Go down and find Crystal Oscillator, which is what we’re using, and we’re going to “select” slowly rising power. This will help save battery life in the long run, even if it loses a bit of accuracy. (it’ll be accurate enough.)

Therefore, our whole byte looks like this:

CKDIV8     1
CKOUT      1
SUT1          1
SUT0          1
CKSEL3     1
CKSEL2     1
CKSEL1     1
CKSEL0     1

0b11111111, or 0xFF in hexadecimal. Now, we can officially set up our hardware to burn these fuse bytes to the GND!

…ha. See what I did there?

Your circuit setup, if using the Arduino UNO as the ISP programmer, should look something like this:


UNO pin 11 (MOSI) -- atmega pin 18
UNO pin 12 (MISO) -- atmega pin 17
UNO pin 13 (SCK) -- atmega pin 19
UNO pin 10 (SS) -- atmega pin 1

Connect all Vcc’s and GNDs.
Put the external 16MHz crystal and connect it to the crystal pins on the ATmega, physical pins 9 and 10, then add the capacitors and ground them, basically the same setup as when you burned the bootloader.

…….And then, I derped.

Turns out when you burn the bootloader it already set the low fuse byte to 0xFF, so I didn’t have to burn the fuse bytes at all!
Ah, oh well, it was a good learning experience to understand datasheets more. 🙂

SO! I loaded my binary watch program, placed it back in the circuit…and it still didn’t work. Gah. Super frustrating.

I decided to go back to basics and look up what’s actually needed for an ATMega328P to work individually on a breadboard, and this Quora post saved my patookie:


This picture shows the basics of what you need for your ATmega:

10Kohm Resistor to RESET pin
AREF and AVCC to Vcc
the Clock on pins XTAL1 and XTAL2(PB6 and PB7) with capacitors tied to GND

And of course the regular Vcc and GNDs. I realized my derpiness and found that I hadn’t connected a 10K resistor to RESET, nor had I connected AREF and AVCC to Vcc. I fixed both of those, restarted the microcontroller, and viola! My code was working!!


Make sure you have not just the right pins, but ALL the pins needed to make sure your microcontroller works.

Here’s the CORRECT pinout for all the pins in my code and external ones I wanted to remember:


Next steps: Schematic for documentation and PCB prep, mock-up on a through-hole PCB to test with coin cell battery as power supply, Deep sleep/low power module additions to code, PCB design