Skip to content

Instantly share code, notes, and snippets.

@emperorner0
Created December 11, 2020 18:58
Show Gist options
  • Save emperorner0/77ecd7094e72cd99168e9c43634a6f07 to your computer and use it in GitHub Desktop.
Save emperorner0/77ecd7094e72cd99168e9c43634a6f07 to your computer and use it in GitHub Desktop.

Language Paradigms: Imperative vs Declarative

Code

Data Science is programming, and while data scientist are 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 solcing methods are utilized with programming languages and frameworks ad are referred to as Programming Paradigms.

There are two main, overarhcing 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 archiecture is one of the earliest described computer architectures that is defined by having a central processer, control units, memory units, and input output mechanisms.) 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 acomplished rather than how it should be accomplished.

Example Paradigms/Languages

Imperative:

  1. Procedural programming: Procedural programming has an empasis on the underlying machine architecture, therefore it functions 'closer to the core', much like a machine language. This nature 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 are meant for specific computation and not the data structure itself and there 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 programatic steps and procedures. These programming languages make up the heart of an information system and deal iwth 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment