5 reasons to use AngularJS in your enterprise application

Original author: Oscar Villarreal

5 reasons to use AngularJS in your enterprise application


image

The current situation in the world of enterprise applications can be described in one word: chaos.

Starting with outdated code, which for N years passed from developer to developer without any documentation. To too complex interfaces that make code too complicated. Before mixing together N technologies in one single application. Let's face the facts: when these things were created, no one thought about their support. Today we are faced with a problem - how to fix all these applications? Where to begin? How to bring common sense to them? How to bring them to the modern technological stack?

This post presents my opinion on why using AngularJS in a corporate environment will not only bring common sense to your applications, but also allow them to grow.

1) Start gradually

In a corporate environment, you are more likely to come across an ugly abandoned project than a new and fresh one. With a project that has been redrawn many times. It is so difficult to understand that developers often throw away code and rewrite it. This, of course, affects both cost and time.

With AngularJS frameworkthis does not happen. You can start by including it in some places of your application that you can slowly start rewriting. Believe me, I did this before, and it really WORKS. And this not only works, but also allows you to lay the foundation for a wonderful application. Given the fact that you can place ng-app anywhere, you can say, for example: “Hey, why don't we start updating this application from the home page”. Then your back end developer writes web services (yes, I'm a front end developer), you start writing your tests with Karma Test Runner and very soon you will suddenly see the Controller, View and Model for the application’s home page. All this is controlled using AngularJSand beautifully encapsulated in its own small world. My friend, you just did a very very good thing.

2) Quick adaptation by developers

Technology is changing so fast that keeping up with the times has become quite a challenge. Either you have the right ways to learn, or you are tormented by reading the various O'Reilly books and trying to figure out how all these things work.

One of the great things that has recently become widely known is the Javascript MVC frameworks. They owe their appearance to the fact that the community realized how difficult it has become to maintain and understand Javascript. Javascript MVC frameworks are a good tool to learn and apply if necessary. For example, in our case, in web applications.

In the case of AngularJS , even if you know absolutely nothing about JavaScript MVC frameworks, you can safely open the official AngularJS website, watch the training video (by the way pretty cool) and after about 10 lessons (15-30 minutes) you will know exactly where to start and how to create the application using the Model, View and Controller (MVC), and, importantly, be able to do all this to test.

This allows large teams to simply go online at any time, get training on the site and, since they are trained from one source, team members can ask each other questions and study the framework at a convenient pace. This is especially important if you have a team whose members work remotely from each other.

3) Performance and scalability

The ability to quickly build a project with all the necessary details is the key to quickly getting started and efficiency. In my memory, there were projects when it took about a week only for everyone to install and familiarize themselves with everything that is necessary for the project. This slows down performance and is a clear sign that something is missing.

To fix this, we can use Yeoman . Yeoman is a workflow consisting of a collection of tools that let you quickly start, run, and assemble projects.

Yeoman works pretty well with AngularJS (which makes sense since they are part of the same family). Yeoman will let you (using generators) create an AngularJS repository that will include the latest version of Twitter Bootstrap, different pieces from angular, Karma Test Runner , etc. And also glue it all together, simply by initializing the repository in a folder with any name (preferably associated with your application). Yeoman will use this name to create the application namespace, and at the same time create a sample of the view associated with the controller sample associated with the test sample.

Such a structure not only allows you to quickly collect something, but also creates the basis for building something much larger. In addition, as soon as you are ready to release, just run the grunt command and your files will be compressed and combined (use ngmin ) and placed in a separate folder. Isn't that wonderful!

Among other things, since you are creating a single page application, everything should be RESTFUL , that is, this application can and will interact with ANY backend if it produces a suitable JSON. Since we separate code and logic, the application will be easier to scale and develop.

4) Tests tests tests

Situation: there are thousands in the project, maybe hundreds of thousands of lines of code. You were thrown right in the middle. There is no documentation and an urgent need to implement a new feature. You start messing around with the code and soon you realize that something else has broken and you have no idea why ... now you have to spend hours, maybe days wandering around the confused code to understand how your changes broke something else ... bad , very very bad.

One of the most important things for maintaining a large amount of code over time is the use of tests. With the Karma Test Runner that AngularJS Generators in Yeoman Will Give You, you can constantly run unit tests in the background. Thus, if you change something and click “save”, your tests will be automatically executed and you will immediately find out if you broke something where you broke it, and if the tests are built correctly, then maybe even why you it is broken.

This is very useful because usually developers insert a new piece of code as follows. They add 10-15 lines, save, and bam, something breaks. Then they comment on 8 lines of code or something. Save, restart, still not working? Not? Clearly, the error should be in these 2-5 lines.

It is much easier to do this than navigate through N files and hidden dependencies and try to understand what the previous developer was thinking when he wrote this.

5) Good community support

Often you get stuck in one piece of code and you have no idea why it does not work. So far, the community has never let me down when it came to helping solve the problem. I ask a question on Stackoverflow or in a Google group and after a few hours or even minutes I get the answer that I needed, sometimes even from the AngularJS development team itself! And this helps not only you, because when your problem is solved, other developers can use this solution for themselves. This speeds up the learning process and the detection of any potential failures. This is, in fact, a process within itself that continues to evolve and grow.

Conclusion: using a very self-confident JavaScript MVC framework like AngularJS- This is a great way to start cleaning up old code, starting small and step by step bringing sanity to your project. If your development team is not at the forefront, they can take AngularJS training online at their own pace and learn how to use it. When they are ready for development, they can turn on Yeoman and start using this “upgrade” in a few minutes using AngularJS , Twitter Bootstrap , Karma Test Runner and many other goodies that Yeoman provides . When a developer begins to build, he can use the development method through testingto create unit tests and test scripts for everything that it collects in AngularJS . This will guarantee that if in the future someone new joins the project and wants to make changes, it will be much easier for him to do this. And with a great understanding of what his code will affect.

AngularJS is not the ultimate bulletproof solution, but it helps pave the way for cool things that will be introduced in newer versions of JavaScript, like Object.observe, a better controlled scope, etc. In theory, these innovations (and I myself believe in this) will bring order and more natural development methods to all applications that use JavaScript.

Also popular now: