Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 20, 2020 02:18 am GMT

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 Im not going to explain the two programming styles Im 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


Original Link: https://dev.to/sylwiavargas/mnemonics-declarative-vs-imperative-programming-b0g

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To