Better Programming

Advice for programmers.

Follow publication

Member-only story

Declarative Versus Imperative Code

Martin Novak
Better Programming
Published in
6 min readNov 10, 2020
cartoon about imperative vs. declarative code
Image source: Author

Believe it or not, you are likely already using multiple programming paradigms as a developer. Because there is nothing more fun than entertaining your friends with programming theory, here is an article that will help you recognize popular paradigms in your code.

For updated information please consider my new post Imperative Vs. Declarative Programming In JavaScript or watching my new YouTube video:

Imperative Code

Imperative programming is how we started with Assembly (1949) and continued with languages like C, C++, C#, PHP, and Java. Procedural and object-oriented programming belong under the imperative paradigm.

Your code is based on statements that change the program state by telling the computer how to do things. In other words, your code is based on defining variables and changing the values of those variables.

It is the ideal programming paradigm for people who have a less-than-innocent fetish for telling machines how to do their thinking.

Procedural code

Procedural code uses procedures to manage its structure. A procedure is simply a set of actions run in a specific order that you are able to call repeatedly instead of jumping by using goto commands.

The above example in C language reads three numbers, uses pointers, and through conditional logic drives the program flow to determine the largest number out of the three. Procedural languages like C can offer you a fairly simple and very computing efficient solution to application challenges.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Martin Novak
Martin Novak

Written by Martin Novak

Martin is a product manager at work, a software developer in his free time, and an entrepreneur at heart.

Write a response