avatarSebastian Streng

Summarize

Programming paradigms — a brief introduction

Programming paradigms — what does that mean? A programming paradigm describes the basic style in which a program is designed. It dictates which principles are applied and which approaches are used.

https://www.seobility.net/de/blog/javascript-crawling/

Shout out to my brother and mentor Tobias Streng If you like this article and want to learn even more about programming in .Net and Angular, please follow us :P

For me as C# developer it was very interesting to find out some other concepts than Object oriented or database- programming. So I decided to write a very small summary about different concepts of programming.

In this article I will address the following topics:

  • Function-oriented programming
  • Client — Server — programming
  • Database-programming
  • Object-oriented programming
  • imperative programming
  • parallel programming
  • logic-based programming

Function-oriented programming:

It is important to understand that these are languages ​​in which there are no value assignments. The most important theoretical basis is the Lambda-Calcul - typical representatives of functional and function-oriented languages ​​are:

Functional programming is the creation of software using Pure Functions. A pure function is a completely normal program function that only has two special properties:

  • The same return value is always supplied for the same input parameters.
  • There are no side effects.

These two characteristics make a pure function comparable to a simple mathematical function y = f(x), which always determines the same y-value for the same x-value.

In practice, this means that the entire program logic of a function works solely with the data from the input parameters and the result is exactly one return value. There are no side effects during the function call, such as changing the status of variables outside the function or the input parameters, writing to the database or a file, or calling other functions that have side effects themselves.

Client-Server-programming:

The client-server model is a way of distributing tasks and services within a network. The tasks are conveyed to programs and then completed by them. These programs are clients and servers.

https://therighttutorial.wordpress.com/2014/06/09/multi-client-server-chat-application-using-socket-programming-tcp/

Client:

A client is a computer or software that communicates with a server (central computer) and uses data and special services from it. The task of the client is to transmit requests to the server and to prepare the data in such a way that the user can read them on his end device. The client itself does not fulfill any server tasks, but only serves as an interface to the user. A typical client is a web browser, for example. In order to display a website, the web browser must contact the web server, which then sends the desired homepage. Only now can the browser display the website. Many clients run in the background as a system service, such as DNS clients.

Server:

A server is usually a computer whose name derives from “To serve”. A server can either only work in a closed (company) network or can also be accessible via the Internet. It´s a kind of contact point in the network or Internet that has to accept, forward and answer many requests. In order for it to be able to cope with this, it is equipped with high-performance hardware appropriate to its task.

Database-programming:

The data to be processed are stored more or less structured in database form. The actual result calculations are done by database queries. For this, universal query languages ​​are used. The best known — SQL (Structured Query Language) and XQuery (XML Query Language) — are just as powerful like algorithmic programming languages ​​of other paradigms.

A database, in short: DB, is a collection ” related” data in a well-structured form. From a technical point of view, a DB can be thought of as a (large) file. With regard to data structuring, a distinction is made between three categories:

  • Flat hierarchy: data representation in the form of two-dimensional tables, if necessary with references to the contents of other tables
  • Strong hierarchy: deep nesting of structures
  • Simply structured: key-value pairs, comparable to a dictionary

Heres an example of a json file:

https://learn.microsoft.com/de-de/sql/tools/visual-studio-code/sql-server-develop-use-vscode?view=sql-server-ver16

Object-oriented-programming:

If you want to learn more about Object Oriented programming, check out my article C# — Object Oriented Programming (OOP).

Objects:

People think object-oriented. They think in terms of objects like table, chair, person and so on. Object-oriented programming languages ​​emulate human thinking and contain abstractions from objects. Object orientation thus describes a way of better imagining the written source code. It is a perspective in software development that describes complex systems using objects and uses classes and methods for this purpose. So the instance of a class is an object. To illustrate this principle of a class more precisely, the person serves as an example. All people have certain characteristics like a name or a date of birth. Every special person is an object.

If properties are now assigned to the Person-class, such as a name, age, height and gender, the superficial image of a person gradually emerges. The specified properties do not yet have any values ​​when the class is created, because here it is only determined which properties the later object should have by specifying the data type from which the respective property originates. Here, a kind of blueprint is used to define what a person is.

If a single object is required, you can use the new() command to create an instance of the Person-class. The constructor is called and the developer is given the opportunity to assign values. For example, here we can create the person Peter with the name Peter, age 41, height 1.82 and gender Male. Peter is the instance/ the formed object of the Person-class. An object can also contain methods.

Methods:

A method can be understood as a kind of “subprogram” in which certain functions of a program can be combined. There are different ways to define methods. Methods can be made visible or invisible to other classes globally in the project using the public and private keywords. It is also possible to define a return data type, which can be assigned as a variable, for example, when the method is called. This is returned in the method body with the keyword return and provided in the method head as the respective data type, e.g. integer. If this is not required, the keyword void is written in the same place in the method header. Furthermore, methods can contain and use parameters. A method can be bound to an object by not being defined as static and being created in the class in which the object’s blueprint is defined. For example, in the previous Person example, you could add the go() method. If the method is not static, it can only be called if it is called using the dot notation behind a class instance, i.e. an object. However, if the method is to be called without being bound to an object, it can be defined as static with the keyword static.

Imperative programming:

Imperative programming is the oldest programming paradigm. According to this paradigm, a program consists of a clearly defined sequence of instructions to a computer.

So the source code of imperative languages ​​strings together commands that determine what the computer has to do and when to achieve a desired result. Values ​​used in variables are changed while the program is running. In order to control the commands, control structures such as loops or branches are integrated into the code.

The imperative programming languages ​​are very concrete and work close to the system. On the one hand, the code is easy to understand, on the other hand, many lines of source code are required to describe what can be achieved in declarative programming languages ​​with a fraction of the commands.

The imperative language can be divided into 3 more parts:

  • structured programming: expands the imperative basic principle with the concrete control structures sequences, selection (selection) and iteration (repetition)
  • procedural programming: divides the task that a program is supposed to take on into smaller subtasks that are described individually in the code. This is how programming blocks are created that can also be used in other programs.
  • modular programming: the individual program components are designed, developed and tested completely independently of one another. Only finally do the individual modules form the actual software in combination

Parallel programming:

In summary, parallel programming is a special case of concurrency where separate entities work together to achieve (generally) high performance and high throughput.

There are two types of parallel programming:

  • implicit concurrency: - very easy for the programmer - Programmer only formulates sequential algorithm and doesn’t care about Organization of the parallel processing - Very high compiler requirements
  • explicit concurrency - must be explicitly formulated in the program by the programmer - Reduced compiler requirements

Concurrency means that several tasks (programs, processes, threads, individual commands, individual operators) that are comparable in their type are carried out at the same time, since several resources suitable for execution are available within the structure level

Async != parallel

Running something asynchronously means it’s not blocked. You run it without waiting for it to complete and move on to other things. Concurrency means running multiple things in parallel at the same time. Concurrency works well when you can break tasks into independent works.

Take rendering frames of a 3D animation, for example. The animation takes a long time to render. When you start rendering in your animation editing software, make sure that it runs asynchronously so that your UI isn’t blocked and you can do other tasks. Now each frame of this animation can also be viewed as an individual task. If multiple CPUs/cores or multiple computers are available, we can render multiple frames in parallel to speed up overall utilization.

Most programming languages ​​offer options for parallelizing processes. However, some languages ​​are designed from the ground up for parallel programming or have this capability inherently:

  • Newsqueak
  • Occam
  • Scratch
  • X10
  • Erlang
  • Chapel
  • Unified Parallel C
  • Rust
  • GO

In my opinion parallel programming has a lot of potential, but also carries a lot of risk. The wrong application can produce a very high error rate and lose a lot of performance. An experienced developer has to decide where and how much parallelization is good. If you make the right decisions, you can save a lot of time and efficiency.

logic-based programming

Logic-based programming is a programming paradigm based on mathematical logic. Unlike imperative programming, a logic program does not consist of a sequence of instructions, but of a set of axioms (axiom = principle recognized as absolutely correct; valid truth that needs no proof), which are to be understood here as a mere collection of facts or assumptions. If the user of a logic program makes a query, the interpreter tries to calculate the solution from the axioms alone.

This example is written in natural language to show the principle:

Facts:

Lucia is Minna’s mother. Lucia is Klaus’ mother. Minna is Nadine’s mother. Rule:

If X is Y’s mother and Y is Z’s mother Then X is Z’s grandmother. Question/Goal:

Who is Nadine’s grandmother? Computer response, deduction from the facts and rules:

Lucy This unspectacular example can easily be expanded to include other family relationships.

Areas of application:

  • Artificial intelligence
  • Databases
  • Expert systems
  • Simulators
  • Generators
  • Mathematics
  • CAD/CAM Systems

Please check out my other articles:

Source:

https://www.freecodecamp.org/news/an-introduction-to-programming-paradigms/#:~:text=What%20is%20a%20Programming%20Paradigm%3F,programming%20problems%20should%20be%20tackled.

Programmmierparadigmen — Christian Wagenknecht

Programming
Programming Languages
Software Development
Object Oriented
Coding
Recommended from ReadMedium