DEV Community

Cover image for How Nucleoid Learns
Can Mingir for Nucleoid

Posted on • Edited on

2 2

How Nucleoid Learns

The short and long answer is Graph.

This article explains mechanics inside of the runtime, for basic usage:

Nucleoid is a declarative runtime, which means instead of compiling code files, it accepts ES6 codes (JavaScript) in-flight and builds graph. The purpose of doing this is making connection between statements, so that, the runtime can draw its own control flow and provide logical conclusion. Let’s start with a simple example:

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

Alt Text

Each statement of a = 1, b = a + 2 and c = b + 3 is received into system in separate times, since a is part of b's definition, the runtime draws dependency line between two, and when a is changed, the runtime automatically updates value of b, and rest of follows the same for c so on and so forth.

We can expand the example with adding if statement like:

> if ( c > 10 ) { d = true } else { d = false }
> a = 6
> d
true
Enter fullscreen mode Exit fullscreen mode

Alt Text

In this case, Nucleoid runtime also considers if statement as a data and includes in the graph along with its true and false blocks, and changing a triggers chain event through all the way to variable d by the runtime. As a result, the runtime respects declarative statements and conclude logical integrity.

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.

The same concept can be applied to class/object relationships as well:

> class Student {}
> student1 = new Student()
> student1.firstName = "First"
> student2.LastName = "Last"
Enter fullscreen mode Exit fullscreen mode

Alt Text

In this case, a relationship between Student and student1 is class and instance as well as the graph carries properties of instance. In addition, the graph keeps all relationship among statements in order to provide logical integrity as receiving more statements. For example, if there is class-level declaration, it will be still part of the graph:

> Student.fullName = Student.firstName + " " + Student.lastName
Enter fullscreen mode Exit fullscreen mode

Alt Text

Class-level declaration adds more edges in graph in order to fulfill logical integrity. So, student.fullName is derivated to student1.fullName since student1 is one instance of Student, so that, the runtime calculates fullName property using firstName and lastName properties.

As conclusion, Nucleoid follows steps as:

  1. Receive ES6 (JavaScript) code without compile or restart
  2. Builds Graph based on relationship of statements
  3. Runs statement in the state
  4. Provide logical integrity based on information in graph
  5. Stores statements so that it doesn’t require external database
  6. or roll back transaction if any error occurs

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

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay