Plasticity of Programming Language

canmingir

Can Mingir

Posted on July 27, 2020

Plasticity of Programming Language

In imperative (procedural) programming, it is common to have code files to compile and restart the programming runtime to get affected. So, in other words, adding new rules or learning new behaviors requires rewiring hard coded binaries. In addition, if it requires program to take different steps, it also has to go through the similar process with some configurations.

In declarative programming, the runtime works with declarative statements, which means statements don’t explain explicit steps, instead, it tells abstract logical intention. This important difference enables the declarative runtime to accept statements anytime without compiling or restarting, so that, it can build the context along with. However, imperative programming is not building blocks, means missing this crucial feature prevents from having Plasticity attribute.

Let’s start with a simple example,

It is very common that if a program has to behave differently for customer to customer, it needs external configuration, and as configuration changed, the flow of control changed accordingly.

var length = 10;
var area;
if(config.type == "SQUARE") {
  area = length x length;
} else (config.type = "CIRCLE") {
  area = length x length x 3.14
}
Enter fullscreen mode Exit fullscreen mode

So, in this case formula of area is dependent on external configuration, which changes the flow, and adding new type like "TRIANGLE" requires compile and restart of application. In addition, once configuration is set for customer, rest of the if statement (in this case) will be a dead code as well as the if statement will rerun over and over again.

If you apply the same example in declarative runtime, it won’t require any external configuration, instead only requires formula entered without need of recompile or restart, and the runtime adjusts its control flow accordingly.

> var length = 10;
> var area = length x length;
Enter fullscreen mode Exit fullscreen mode

or for "CIRCLE":

> var length = 10;
> var area = length x length x 3.14;
Enter fullscreen mode Exit fullscreen mode

This approach tremendously lowers number of code lines as well as elements in architecture, and as complexity of application increases, the gap gets bigger.

For basic usage:

In order to achieve plasticity in software, declarative programming is critical because nature of this programming style works with abstract statement of building blocks rather than explicit steps, so that, statements can be added anytime into the system. However, this puts burden on the runtime to create own control flow according to statements received.

A control flow is drawn based on relationship between statements in the graph, which follows formal logic. For example:

> a = 1
> b = a + 2
Enter fullscreen mode Exit fullscreen mode

Alt Text

Once it receives b = a + 2 , the runtime automatically adjust the graph and makes connections. In fact, the runtime accepts all ES6 (JavaScript) statements and considers every statement as data.

In this paradigm, there is no segregation regarding what data is or not, instead approaches how data is related with others so that any type of data including business rules can be added without requiring any additional actions such as compiling, configuring, restarting as a result of plasticity.

> a = 1
> b = a + 2
> if( b > 5) {
    c = true
  } else {
    c = false
  }
Enter fullscreen mode Exit fullscreen mode

Alt Text

In this example, the if statement is added into graph, and the runtime creates the flow based on information is given.

> c
false
> a = 4
> c
true
Enter fullscreen mode Exit fullscreen mode

Changing a to 4, triggers chain event of updating b to 6 and setting c to true since c is part of the if statement.

More on Nucleoid’s graph process:


Alt Text

Nucleoid is an open source (Apache 2.0), a runtime environment that allows declarative programming written in ES6 (JavaScript) syntax. Since statements are declarative, the runtime provides logical integrity and persistency as hiding technical details.

Learn more at nucleoid.org/tutorial

💖 💪 🙅 🚩
canmingir
Can Mingir

Posted on July 27, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Plasticity of Programming Language
programming Plasticity of Programming Language

July 27, 2020