In computer science, we learned about different programming paradigms, and one that always fascinated me was declarative programming. This type of programming differs from imperative programming (such as C, Python, Go, etc.) in that, instead of telling the computer HOW to do something step by step (like a cooking recipe), you simply specify WHAT it has to do.
Declarative Programming
In our studies, we work with two declarative languages: Lisp and Prolog. Of these, Prolog stood out for its ability to solve logic problems. A classic “Hello World” in Prolog involved solving family questions through a family tree, a simple but powerful example of how declarative programming could facilitate complex tasks with simplicity.
Arrival of true declarative programming with Generative AI
Well, with the generative AI revolution, true declarative programming has arrived. For example, here’s a button.
When learning frontend development with modern frameworks such as Vue, Angular or React, a common exercise is to create an application to manage a ToDo list. Typically, a single page application (SPA) is created where, in addition to a list, a text input with a button to add a new task is included.
We have gone a step further by creating an updated, much more powerful and flexible version of one of these applications, and best of all, 100% declarative. The important thing here is that we don’t use the AI just to generate the code, but the AI itself, based on a prompt, actively manipulates the task list.
![](https://montevive.ai/wp-content/uploads/2024/08/Captura-de-pantalla-2024-08-19-a-las-11.14.38-1024x1005.png)
Application implementation with AI
For its implementation, we use a workflow of n8n connected to a Telegram bot. As LLM model, we used GPT-4o mini and for storage we used Redis with persistence.
![Screenshot of a list of reminders in a chat app](https://montevive.ai/wp-content/uploads/2024/08/screenshot-de-una-li-1.jpg)
In this example, you can see how I ask the AI to list pending reminders for me. The power of natural language processing means that I don’t have to send a structured command or a specific keyword; the AI is able to detect the intent. Doing this with an imperative language would require adding additional, often complex, logic.
![](https://montevive.ai/wp-content/uploads/2024/08/Captura-de-pantalla-2024-08-19-a-las-11.16.45-882x1024.png)
Adding and deleting tasks with AI
Adding tasks or reminders is equally simple. To delete tasks, it is also not necessary to give it the exact words, since, in the black box of the model, the AI analyzes the options and looks for the most similar one. If there are two very similar tasks and the AI is in doubt, it will ask us directly which one we are referring to.
![Screenshot of a WhatsApp conversation with a list of reminders.](https://montevive.ai/wp-content/uploads/2024/08/screenshot-de-una-co-3.jpg)
All the magic of this lies in a simple prompt.
And here’s the magic, a system prompt, 100% declarative.
Acts as a JSON job expert. The user passes you the current array of the reminder object as context. A reminder object has the following fields:
- content: string with the content of the reminder. Put only the relevant content (not the intent but the subject).
- created_at: RFC3339 date and time when the reminder was created
- updated_at: RFC3339 date and time when the reminder was updated
Additionally, the user provides a reminder intent. It should be to add, update, or delete a reminder.
You also receive the current date and time.
You should return a JSON object with the following structure:
- action: enumeration string indicating the action performed ("list", "add", "update", or "delete")
- reminders: updated array of the reminder
The Future of Programming
As nVidia CEO Jensen Huang rightly says, the programming language of the future is English. And at Montevive.ai we completely agree.
![](https://montevive.ai/wp-content/uploads/2024/08/image-edited.png)
“Programming language should be human”
-Jense Huang, nVidia CEO
The flexibility and ease offered by this type of programming is immense, although there is always an argument against it. A frequent challenge is the energy and computational expense, seemingly excessive for a relatively simple task. However, costs are constantly optimized and, in the long run, flexibility and efficiency outperform traditional methods.
Conclusion
In short, we are moving into a new era of programming, where declarative programming meets generative AI to facilitate our interaction with technology in ways never seen before. Welcome to the era of future programming.
I hope you find this new perspective on programming and the power of generative AI interesting and useful. 🚀🔥
Imperative programming is dead. Long live declarative programming!