Mnemonics: declarative vs imperative programming
Tags: javascript, beginners, react, computerscience
Published: 2020-11-20 02:18:34

Learning to code is not easy when English is not your first language. It gets especially tough with all the vocabulary and expressions that you wouldn't usually encounter in everyday context. For me, one of such struggles has been remembering declarative and imperative programming — which one is which. I've read a couple of posts and definitions and while they made perfect sense, I'd have to google it again after half a year. ✨ This week, I finally found two mnemonics that work for me and I'm happy to share them in hope that they would work for you as well:
 
- [Mnemonic one: age of empires 🧙‍♂️](#mnemonic-one-age-of-empires)
  - [Imperative programming — the Romans!](#imperative-programming-the-romans)
  - [Declarative programming: Byzantines, Angles, Saxons, and Franks!](#declarative-programming-byzantines-angles-saxons-and-franks)
- [Mnemonic two: birthday cake 🎂](#mnemonic-two-birthday-cake)
  - [Imperative programming — baking!](#imperative-programming-baking)
  - [Declarative programming - plate with a cake](#declarative-programming-plate-with-a-cake)

I'm also curious — how did you remember them? I heard that that's something even non-native speakers find confusing.

**note**: in this post I’m not going to explain the two programming styles — I’m just offering a mnemonic that helped me remember for good which one is which. If you want to understand the two styles better, check [this great post on freecodecamp](https://www.freecodecamp.org/news/imperative-vs-declarative-programming-difference/).

***

# Mnemonic one: age of empires 🧙‍♂️

![Roman sculpture](https://dev-to-uploads.s3.amazonaws.com/i/6wdksy1p4uroo6x1h72w.jpg)

## Imperative programming: the Romans!
The word 'imperative' sounds almost like the Latin *imperium*, which means *empire*. So, whenever I need to give an example of an imperative programming, I think about all the work that needs to be put into building a massive civilization — I think about the Romans and how they laid all the roads and built all the infrastructure and aqueducts. This feels awfully similar to DOM manipulation with *vanilla JS* or doing anything with *C* — it's the long way, oftentimes to some degree from scratch. 

## Declarative programming: Byzantines, Angles, Saxons, and Franks!
Okay, the sun has set on the Roman Empire, other folks arrive on these lands, look around, think that these roads and baths are quite okay, maybe they just change the city name road sign and _declare_ it theirs. That's *React*, which is based on delightful abstractions.

***

# Mnemonic Two: Birthday cake 🎂

![Pavlova cake](https://dev-to-uploads.s3.amazonaws.com/i/evj0azoxbw20rjat9pzs.jpg)

## Imperative programming: baking!
It's your best friend birthday. You make a [Pavlova cake](https://www.allrecipes.com/recipe/15532/the-best-pavlova/) because you know they love it. Baking itself takes like 5h but you also need to go get all the ingredients and then clean the kitchen afterwards. Easily, 7 hours of work. This is how it feels to do DOM Manipulation with *vanilla JS* or do anything with *C* — it's the long way, oftentimes to some degree from scratch. 

## Declarative programming: plate with a cake
Now, imagine some dude comes late to the party and everything is prepared and he didn't bring anything. Someone asks him what he's brought, he rushedly grabs a plate and puts a piece of cake you baked and hands it to the person without much chit-chat — the person seems really happy with what they got! Having this piece of cake in their hands, they don't care much about the process of its creation. That's _React_, using what's already there and making it easy and fuss-free to get what you want. You may, however, later learn that in the process of the cake creation a bunch of strawberries were used and you are awfully allergic to all berries but didn't think to ask ¯\_(ツ)_/¯ 

***
Cover photo by by [Aline Ponce](https://pixabay.com/users/ponce_photography-2473530/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1470226)from [Pixabay](https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1470226)
Body image by ERIND DERSTILA from [Pexels](pexels.com)