Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imperative vs Declarative build systems

Tags:

maven

gradle

ant

I have recently started using Gradle as a build system. They first comparison that Gradle makes with the likes of Ant and Maven is that, Ant is an imperative build system, whereas Maven is a declarative build system. While Gradle is a declarative build system without the rigidity enforced by Maven.

I wanted to understand these terms declarative and imperative better when it comes to talking about build systems.

like image 910
Ankit Dhingra Avatar asked Feb 19 '13 10:02

Ankit Dhingra


People also ask

What is the difference between imperative and declarative?

Declarative programming is a programming paradigm … that expresses the logic of a computation without describing its control flow. Imperative programming is a programming paradigm that uses statements that change a program's state.

What is the difference between declarative configuration and imperative configuration?

The declarative approach requires that users specify the end state of the infrastructure they want, and then Puppet's software makes it happen. The imperative/procedural approach takes action to configure systems in a series of actions.

Is terraform imperative or declarative?

Some examples of popular IaC tools that use the declarative programming paradigm include Terraform, Puppet, Ansible, Salt, and CloudFormation.

Is Ansible imperative or declarative?

Both Ansible and Puppet are declarative systems.


1 Answers

In short, an ant script tells the ant tool what to do - "compile these files and then copy them to that folder. Then take the contents of this folder and create an archive."

While a maven pom declares what we would like to have as the result - "here are the names of the libraries the project depends upon, and we would like to generate a web archive". Maven knows how to fetch the libraries and where to find the source classes on it's own.

While ant gives you more flexibility, it also forces you to constantly reinvent the wheel.

Maven on the other side requires less configuration, but may feel too constraining, especially if you are used to a different workflow.

EDIT: An important aspect of the ant-maven comparison is that maven has a convention, describing where the files should lie, where the dependencies are found, where to put the resulting artifact, while ant does not.

So you can think of using maven like riding a bus - you select the stop where you enter and the one where you leave. Using ant is like driving a car - you have to do it yourself. You dont have to tell the bus driver what to do, but the stops may be too far from where you want to go.

EDIT2: 'Reinventing the wheel' metaphor seems to be less clear than I had hoped. This is what I mean:

Without sensible defaults/conventions, you have to define the project structure and the build lifecycle explicitly for each project, often making it a matter of taste and opinion. As preferences vary between teams and companies, so do build processes. This requires more cognitive effort for new project members and later maintainers. Depending on the experience and expertise of the developers, the final solution may be hard to extend and use.

As I said in a comment below, while best practices for ant builds exist, they still have to be implemented for each project, or copy-pasted from project to project, instead of becoming an out-of-the-box default of the build tool itself.

Maven is a bit too far on the other side of the trade-off for my taste. Changing the defaults is not as easy as it could and should be.

like image 193
kostja Avatar answered Oct 06 '22 20:10

kostja