Montevive

/ Blog /

News

Montevive

How Generative AI Transformed the Programming Paradigm: From Imperative to Truly Declarative

·erobles·Artificial Intelligence
How Generative AI Transformed the Programming Paradigm: From Imperative to Truly Declarative

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 (like 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 worked with two declarative languages: Lisp and Prolog. Among these, Prolog stood out for its ability to solve logic problems. A classic "Hello World" in Prolog involved solving family-related questions through a family tree, a simple yet powerful example of how declarative programming could simplify complex tasks.

The Arrival of True Declarative Programming with Generative AI

Well, with the generative AI revolution, true declarative programming has arrived. For proof, here's an example.

When learning to develop frontend with modern frameworks like Vue, Angular, or React, a common exercise is to create an application for managing a to-do list. Typically, a single-page application (SPA) is created where, besides a list, a text input with a button to add a new task is included.

We have taken a step further by creating an updated, much more powerful and flexible version of one of these applications, and the best part, it's 100% declarative. The key here is that we are not using AI just to generate the code, but the AI itself, based on a prompt, actively manipulates the to-do list.

Implementing the Application with AI

For its implementation, we used an n8n workflow connected to a Telegram bot. As the LLM model, we used GPT-4o mini, and for storage, we used Redis with persistence.

In this example, you can see how I ask the AI to list my pending reminders. The power of natural language processing means I don't have to send a structured command or a specific keyword; the AI can detect the intent. Doing this with an imperative language would require adding additional, often complex, logic.

Adding and Deleting Tasks with AI

Adding tasks or reminders is equally simple. To delete tasks, it's also unnecessary to provide the exact words, as, inside the model's black box, the AI analyzes the options and looks for the closest match. If there are two very similar tasks and the AI has doubts, it will ask us directly which one we are referring to.

All the magic of this lies in a simple prompt.

And here is 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.

> «Programming language should be human»

-Jensen Huang, nVidia CEO

The flexibility and ease offered by this type of programming are immense, although some counterarguments always emerge. A frequent challenge is the energy and computational cost, which seems excessive for a relatively simple task. However, costs are constantly being optimized, and in the long run, the flexibility and efficiency surpass traditional methods.

Conclusion

In short, we are moving towards 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!