Skip to main content

Declarative vs Imperative Programming Neeraj Mishra The Crazy Programmer

When we talk about the programming we mainly focus on languages and codes but an important part of writing good code or selecting the correct programming language for the problem we are working on is to understand the language itself. In this article, we will discuss the different types of Programming Paradigm which are present in programming.

Let us first understand the meaning of Programming Paradigm, it may sound something difficult but it simply is a division of languages based on how they work. There are mainly 4 types of paradigm: 

  • Imperative or Procedural Programming
    • E.g. C, Pascal etc.
  • Declarative Programming
    • E.g. SQL
  • Logical Programming 
    • E.g. Prolog
  • Object Oriented Programming
    • E.g. Java, C++ etc.

Let’s see an example to understand the difference between Imperative and Declarative Programming. Suppose you are trying to build a house, if you go to your engineer and tell him how many rooms you want and where you want them then you will come under a declarative programming paradigm. On the other hand, if you tell your engineer that you should follow these particular steps (e.g. build a wall here etc.) and then my house will be built then you will come under imperative programming.

Declarative paradigm expresses what to do.

Imperative paradigm expresses how to do it.

In an imperative language, we declare each and every step which needs to be done, like in C where we go with the logical flow of the program and write that down in steps.

In declarative language, we just specify what we want and the languages under the hood do the work for us and bring us the result. In SQL we just write which entries we need from a table and then it directly gives us the result, we do not specify how it should search in a table or anything else.

Imperative languages, in general, are easy to understand as the flow is clear to programmers but have long code. Flow in declarative languages isn’t that clear and therefore is difficult to debug but as we just mention steps the code length is short.

Declarative vs Imperative Programming

Declarative Imperative
The developer generally write code about what needs to be done Developer write code about how something should be done
Code length is short in general Code length is generally large
Logic Programming and functional programming falls under the Declarative Paradigm  Structured Programming and Procedural programming falls under Imperative Paradigm
Difficult to debug Easy to debug 
E.g. SQL, Prolog E.g. C, C++

Note: All the programming paradigms are not necessarily disjoint, the same language may follow traits from two different paradigms.

I hope now you got a clear idea about both programming paradigms. Comment down below if you have any queries.

The post Declarative vs Imperative Programming appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/2UauF09

Comments

Popular posts from this blog

Difference between Web Designer and Web Developer Neeraj Mishra The Crazy Programmer

Have you ever wondered about the distinctions between web developers’ and web designers’ duties and obligations? You’re not alone! Many people have trouble distinguishing between these two. Although they collaborate to publish new websites on the internet, web developers and web designers play very different roles. To put these job possibilities into perspective, consider the construction of a house. To create a vision for the house, including the visual components, the space planning and layout, the materials, and the overall appearance and sense of the space, you need an architect. That said, to translate an idea into a building, you need construction professionals to take those architectural drawings and put them into practice. Image Source In a similar vein, web development and design work together to create websites. Let’s examine the major responsibilities and distinctions between web developers and web designers. Let’s get going, shall we? What Does a Web Designer Do?

A guide to data integration tools

CData Software is a leader in data access and connectivity solutions. It specializes in the development of data drivers and data access technologies for real-time access to online or on-premise applications, databases and web APIs. The company is focused on bringing data connectivity capabilities natively into tools organizations already use. It also features ETL/ELT solutions, enterprise connectors, and data visualization. Matillion ’s data transformation software empowers customers to extract data from a wide number of sources, load it into their chosen cloud data warehouse (CDW) and transform that data from its siloed source state, into analytics-ready insights – prepared for advanced analytics, machine learning, and artificial intelligence use cases. Only Matillion is purpose-built for Snowflake, Amazon Redshift, Google BigQuery, and Microsoft Azure, enabling businesses to achieve new levels of simplicity, speed, scale, and savings. Trusted by companies of all sizes to meet

2022: The year of hybrid work

Remote work was once considered a luxury to many, but in 2020, it became a necessity for a large portion of the workforce, as the scary and unknown COVID-19 virus sickened and even took the lives of so many people around the world.  Some workers were able to thrive in a remote setting, while others felt isolated and struggled to keep up a balance between their work and home lives. Last year saw the availability of life-saving vaccines, so companies were able to start having the conversation about what to do next. Should they keep everyone remote? Should they go back to working in the office full time? Or should they do something in between? Enter hybrid work, which offers a mix of the two. A Fall 2021 study conducted by Google revealed that over 75% of survey respondents expect hybrid work to become a standard practice within their organization within the next three years.  Thus, two years after the world abruptly shifted to widespread adoption of remote work, we are declaring 20