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 two: birthday 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.
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.
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.
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.
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 ¯_(ツ)_/¯