DEV Community

Cover image for Understanding Composer
Yahaya Oyinkansola
Yahaya Oyinkansola

Posted on

Understanding Composer

Intro

Composer is a popular tool used when building web applications and websites with PHP. In this article, i would give a short discussion about what Composer is and the advantages it brings to your project.

What is Composer?

Composer is a dependency manager that provides a standard way of managing all the dependencies your project requires in a convenient and easy way. With Composer, you declare all the packages you need and Composer would manage (i.e install/update/remove) those packages for you.
You could argue that managing these packages can be done manually, but let me ask this simple question, what if the creator of the package updates the code or rolls out a new feature?, you would have to go and get the new code to replace the old one, doing this for one or two packages might not look stressful but on the long run when you start dealing with multiple packages, it starts to become a pain in the neck to manage all of them manually, especially when those packages depend on other packages!, trying to handle it yourself can lead to a lot of errors that can be very hard to debug and fix.
There are 2 terms that seem to be quite confusing in relation to this topic, package managers and dependency managers.

What's the difference between a package manager and a dependency manager?

In the software development world, this two terms seem to be interchanged quite a lot, i am here to tell you that there isn't much of a difference between them, a package manager can be a dependency manager and vice versa, you heard it from me first 😏😏, the reason for this distinction is because of the operation being carried out. I said from the beginning that Composer is a dependency manager but do you know it is also a package manager?, this is because normally Composer is managing packages, but what makes it different from other package managers like NPM is that it manages packages at the project level, not at the system level. Okay so what does that mean?, with a package manager like NPM, you can install packages on your system globally along with configurations that would be used to build multiple projects, but the case is not the same with a dependency manager because these packages are managed within the project and any configuration created is only for that specific project. Composer supports installing packages globally too, but it was not created for that purpose. Composer is more of a dependency manager than a package manager because it's main Job is to manage dependencies that require other dependencies.

The Advantages that Composer provides

  1. Composer automatically generates an autoloader file for your project that helps you import all the packages you have installed. If you have ever written an autoloader file, you know it can be quite stressful to create. Composer has simplified this process, and you only need to require the file in your project.

  2. Composer makes it easier for you to collaborate with other developers as they only need your composer.json file to install all the project dependencies and get up to speed.

  3. You can be confident about the packages you install because it is gotten from a reliable source, and in a case where a package does not work the way you expect or is causing problems within your project, you can easily remove it.

  4. As mentioned before, Composer grabs any package required by the package you are installing, this produces faster development and productivity because you only need to be concerned about the package you want to install, while Composer handles the rest for you.

Conclusion

Composer is very useful and i see no reason why you shouldn't be using it, but it is good to always understand why you need to use a tool before starting to use it, i personally didn't see the need of using Composer before but now it has become important to me. As your project begins to grow, using Composer would become more of a necessity as it would help your project scale better. You can learn more about composer from Composer's website. Thanks for reading!.

Top comments (2)

Collapse
 
anniegardner profile image
AnnieGardner

what is Understanding Composer please define? comment rendre un homme fou

Collapse
 
kansoldev profile image
Yahaya Oyinkansola

What it means is having knowledge of what Composer is doing in your project so that you can be able to use it better