This process, where you basically tell a computer how to do a task is generally known as programming but don’t be mistaken. It’s just the head-side of the coin.
Giving computers instructions is just a facet of programming called imperative programming. There is another facet called declarative programming and some web developers don’t really recognize it as programming… it is.
The maxim of declarative programming revolves around telling a computer what and not how. To be specific, we tell the computer what we want, and we leave the language interpreter to determine the steps or process to be undertaken to accomplish the task.
Now this may sound fictional but this approach can help in building the web of the future that we are all hoping for.
It’s not seen easily
The subtlety of declarative programming is largely a result of how it is. Let’s put this into an example. Say, you asked your mom to make you some lemonade. Of course, if you programmed your mom, you’ll be telling her the process to make a lemonade step-by-step. But you can’t program your mom (you’ll be in big trouble if you try) so what you can do is ask her for the end result and that is to make you lemonade (please). And if your mom wanted to, she would process “I want some lemonade” into steps like getting a glass of water, getting ingredients and so on.
This is what declarative programming is. You basically declare what result you want to accomplish and leave out the logic of the process needed to arrive to the result.
In HTML, if we want to show an image, we’ll just use and <img> tag and the system will be able to understand that and create a process (i.e. pull out the url of the image from the server, determine the location of the image to render, scale it into the screen, and show it to the user).
Of course, we may not see this as programming, but it is. Realizing that using the <img> tag is basically saying to the browser that you need an image and the user agent will takes the steps for you.
One of the other factors that pulls the strings behind declarative programming on the Web is that somehow magically, it just works out of its own. We know HTML and CSS involved a lot of work to implement, and we somehow fail to see them as declarative programming because we see them as simple output instructions.
One of the real world applications of declarative programming is API development. APIs are implemented using declarative programming and so, developers have less stressful experiences using them.
APIs help in such a way that it saves the developer, and the website, from lots of step-by-step instructions in pulling out a result they want. Rather than telling the website the specific steps to yield to an end result, we could just use an API that does the explaining for us.
Better and more complex
Once we see the real use of declarative programming, it’s difficult and nearing impossible to un-see it. Declarative programming makes the Web work easier and more efficiently.
Realizing this importance will lead us to a better future, computer-wise. Instead of replacing declarative programming languages with easy-to-use imperative programming, we can resort to creating better declarative languages that can be used by imperative programmers. In this process, we will be able to create better systems.
First and foremost
The first step in building a web-based tool is often programming the tool and make it do whatever it is that you want it to do. However, in the philosophy of declarative programming, you can start by defining the language suited for the end results you desire.
Now, you have a few choices to start with. You can start initially with high level format choices or end up with the details of the data structure. You need to make these choices as early as possible for you to improve the way you organize your work, and later, your imperative implementation.
Finding success using declarative programming will be a long piece of land to till. There are challenges that await you, roadblocks that are even more difficult to hurdle than those you encounter in imperative programming. You need to be clear and concise with what you do, but you also need to be knowledgeable about imperative programming to easily understand what needs to be declared. It’s a difficult journey, but it’s also rewarding because declarative programming tends to live longer than imperative programming.
So, next time, start adapting a declarative-first mindset and see what languages are available for you to describe your end result. And when worse comes to worst, write your own simple languages. And the moment you understand what you want to create, start it alongside with a language interpreter. And who knows what you’ll end up creating in the long run.