Programming Paradigms: Imperative vs Declarative

Samuel Middleton
3 min readDec 11, 2020

Data Science is programming, and while data scientist is generally more concerned with the P-Value of a statistical test it is important to have a solid grasp on the basics of computer science. Data science is built on a long tradition of computer science, and computer science is built on a foundation of problem-solving methods based around math and logic. These problem-solving methods are utilized with programming languages and frameworks ad are referred to as Programming Paradigms.

There are two main, overarching paradigms when it comes to problem-solving in programming.

  • Imperative: Imperative programming languages are closely tied to machine architecture, and particularly von Neumann Architecture. (The von Neumann architecture is one of the earliest described computer architectures that is defined by having a central processer, control units, memory units, and input-output mechanisms.) The imperative program works by changing the state of the machine by following procedural instructions step by step. The machine state is changed through assignment statements and operations. Data is handled through variables, with transversal using loops and iterations.
  • Declarative: Declarative programming is a paradigm that emphasizes the logic of computation without explicit control of flow. It also has a focus on parallel programming, with a focus on what needs to be accomplished rather than how it should be accomplished.

Example Paradigms/Languages

Imperative:

  1. Procedural programming: Procedural programming has an emphasis on the underlying machine architecture, therefore it functions ‘closer to the core’, much like a machine language. This naturally means that it also functions faster than something that is completely dynamic. It was an early branch of imperative programming and allowed the reuse of code parts making programming more efficient and starting the building blocks for Object-Oriented Programming. A few examples are C, Java, and Pascal.
  2. Object-Oriented Programming: OOP is programming that utilizes classes and objects to communicate and move data. The basic unit of OOP is the object and all computations are performed on objects. The focus with OOP is on data rather than procedure. This paradigm enjoys several advantages and benefits, such as security, inheritance, reusability, and flexibility. A few language examples are C++, Python, and Visual Basic .NET.

Declarative:

  1. Functional programming: Functional programming has its roots in mathematics, where problem-solving is more concerned with method instead of data. The central unit for FP is the function which is meant for specific computation and not the data structure itself, thus data is loosely coupled to the function. Some examples of functional programming languages would be: Scala, Javascript, Lisp
  2. Database Programming: Somewhat confusingly, database programming is based on the methodology of data and its movement. Database programming functions on statements that extract data rather than programmatic steps and procedures. These programming languages make up the heart of an information system and deal with file creation, data entry, deletion, updates, queries, and reporting. The major example of database programming is SQL (Structured Query Language).

Conclusion

These two paradigms make up the bulk of all problem-solving methods within computer science, and therefore also data science. It is important to understand your problem and analyze your use case so that you can find the most optimal paradigm to find a solution.

Originally published at http://github.com.

--

--

Samuel Middleton
0 Followers

Data Science | Data-Driven | Analytics | Communicator | Python, PyTorch, Machine Learning, NLP, Computer Vision | Seeking Full-time Data-Analyst Position