Why there is no NullPointerException in Declarative Programming

Can Mingir
Jun 26 · 3 min read
Image for post
Image for post

It is better to start with agreeing on what declarative programming is because no argue that declarative programming is an abstract term with many definitions, and for this particular case, we are going to focus on the control flow.

We can easily roll out one, if the control flow is managed by programmers, it is imperative (procedural) programming. Here is the quick example for that:

account.balance = 1000;if( account.balance > 500 ) {
account.status = "OK"
} else {
account.status = "LOW"
}

It is typical if/else statement, but the problem is when changed, the same if/else statement has to rerun.

account.balance = 1000;if( account.balance > 500 ) {
account.status = "OK"
} else {
account.status = "LOW"
}
account.balance = 400;if( account.balance > 500 ) {
account.status = "OK"
} else {
account.status = "LOW"
}

If/else statement might be a part of function, but it is going to look like this when expanding of code lines into a call stack.

However, in declarative programming, it is enough to define if/else statement once, and the declarative runtime will correct variables accordingly, means the runtime will provide logical integrity:

> if( account.balance > 500 ) {
account.status = "OK"
} else {
account.status = "LOW"
}
> account.balance = 1000
> account.status
"OK"
> account.balance = 400
> account.status
"LOW"

The runtime automatically updates when changed.

Here is the problem starts,

if( account.payment.address.state == "NY" ) {
..
}

When there is a property like without actually defining each object, the runtime will throw some exception like because the burden is on a programmer to verify each object, and this execution has to return something not programming language specific like , etc., but again not .

The declarative runtime cannot just throw technical exception because those don’t have any meaning to end users. Instead, it has to follow formal logic, which most declarative programs do, so that it has to wait until all variables are defined, then run the if/else statement.

> if( account.payment.address.state == "NY" ) {
account.payment.tax = 8.82
}
> account.payment = new Payment()
> account.payment.address = new Address()
> account.payment.address.state = "NY"
> account.payment.tax
8.82

In conclusion, the declarative runtime is responsible to manage control flow in formal logic with including to provide logical integrity and hiding all technical details. This concept reduces complexity of code lines and helps developers to spends more time on functionalities.

P.S. It is worth to mention, word of in here is being used as phrase rather than specific problem to Java.

Image for post
Image for post

Nucleoid is 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.

Join project at gitlab.com/nucleoid/nucleoid

Nucleoid

Declarative Runtime System

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store