Mnemonics: declarative vs imperative programming

sylwiavargas

Sylwia Vargas

Posted on November 20, 2020

Mnemonics: declarative vs imperative programming

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:

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.


Mnemonic one: age of empires šŸ§™ā€ā™‚ļø

Roman sculpture

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

Imperative programming: baking!

It's your best friend birthday. You make a Pavlova cake 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 Poncefrom Pixabay
Body image by ERIND DERSTILA from Pexels

šŸ’– šŸ’Ŗ šŸ™… šŸš©
sylwiavargas
Sylwia Vargas

Posted on November 20, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related