Plasticity of Programming Language
Tags: programming, javascript, node, ai
Published: 2020-07-27 15:51:54

---
description: Nucleoid accepts declarative statements anytime without compiling or restarting, so that, it can build the context along with.
---

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.

```javascript
var length = 10;
var area;
if(config.type == "SQUARE") {
  area = length x length;
} else (config.type = "CIRCLE") {
  area = length x length x 3.14
}
```

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.

```javascript
> var length = 10;
> var area = length x length;
```

or for `"CIRCLE"`:

```javascript
> var length = 10;
> var area = length x length x 3.14;
```

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:

{% link https://dev.to/nucleoid/hello-world-with-nucleoid-jo0 %}

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:

```javascript
> a = 1
> b = a + 2
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/y9lwdht78ujtovjzlx28.png)

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.

```javascript
> a = 1
> b = a + 2
> if( b > 5) {
    c = true
  } else {
    c = false
  }
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/z72ej1m511strrny37he.png)

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

```javascript
> c
false
> a = 4
> c
true
```

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:

{% link https://dev.to/nucleoid/how-nucleoid-learns-210l %}

---

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wfyvyod0j3llowi236t2.png)

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](https://nucleoid.org/tutorial/)