Sometimes ago I found myself in the situation that I used to write lot of common code for several projects. If you have worked/created several ideas with similar stack you may have found that there are lot of parts of the code that are similar and probably even duplicated with slightly changes.
It is not code duplication, it is common functionality between different projects. Some examples of code that can be used on both applications that is not related directly to a feature and that could be reused are:
- Configuration for rendering views, loading modules, folder structures
- Configuration of the libraries, packages, continuous integration setup, access to services, profiles
- Main common functionality: user management, authentication, authorization
- Boilerplate code to start looking advances on your ideas: main page setup
On top of that, it is always good to have a way to:
- Export and visualize metrics
- Connections to monitoring systems
- Common management api endpoints: status codes count, exceptions thrown, latency, bandwidth required…
I used to have projects where I worked on some of these features and copy them to other projects. These became a really boring task that could be automatized. Started to do some code generation with Model to Model (M2M) or Model to Text (M2T) transformations and using Visual modeler (Eclipse EMF and GMF), a tool that based on a UML design it translated the information into code. The problem is that the world of applications have changed a lot recently and several things were not contemplated properly in these tools: Lack of ui support and lot of memory requirements.
I decided I was going to build something to use on personal projects in a kind of template orchestrator when I discovered Yeoman. I have to say it is one of the tools I have found more useful in the last years.
In my opinion, Yeoman is a great tool for:
- Kickstart new projects
- Learn new technologies/stack
- I often found myself about learning some new technology or setup. Used in the past some express tutorials and had interest in react. The problem was that the wiring for everything looked a bit complicated and all I needed was a bit of a quick feedback to start getting into deep matters. I love to learn something but if it takes a whole day to see something useful it is not going to be easy to explain to others.
- Learn best practices
- Having a look to generators done by experienced programmers on that area give you a sense of how an app should be structured or the purpose of it.
- I normally have a look once a month to see what the Yeoman team has done
- Avoid boilerplate code by hand. Why do we have machines then?
- Compose generators to make your own based on others work
- Transfer that inherit knowledge in a company that is not written in any documentation: Classes, way of transferring data from one layer to another, services architecture…
I have sometimes a hard time maintaining the project with yeoman for adding new things: Sometimes the project is created, you modify it and then you need to add something else. Yeoman does not support really well dynamic changes, although I think this is a beast on itself.
Generators I use
I used a couple of generators in the past for pure learning and after that used them on different projects:
- Angular full stack: angular on the client side while express on the backend side.
- React full stack: react for ui prototyping. A great resource for see all the new cool kids in town. Learnt and still learning, really good for a study group or a immersive weekend with react. If you want to see the project generated just have a look to the starter kit, which is what the generator is based.
- Jhipster: I am mostly a java developer. I love this project and learnt a lot from it. From data access, dto translation, controllers, services, etc… to indexation of information and frontend generation. This project has everything including a great documentation. The only down on my side is that the frontend work is generated inside the maven project(I am more on the idea of having backend and frontend separated). This is a blog post by itself.
How to use it
The main page has great documentation. You can find here.
Just as an overview, here are the two main commands I used:
npm install -g yo bower grunt-cli gulp
npm install -g generator-jhipster
Create project with a generator. Example: jhipster
That’s it. Really simple to setup. Just follow the instructions and start exploring the code 🙂
Contributing to open source project
One of the beauties of working with open source projects is the possibility to contribute. Some of the ideas that have been going around in my head is the possibility to contribute to the Jhipster generator or even use it to do an application setup following the concepts I have about ideal architecture (frontend and backend separated).
Devs should give it a go as part of training
I think this tool is great for everyone that develops, although the main gain is on junior developers. They can build something of really high quality using one of these generators. Really great to build something on the weekend and put it on the github profile for those interviews in the bay.
Use yeoman in your company for easy ramp up on Junior devs
I think about this tool and how to incorporate it in my company. I have seen lot of copy paste, boilerplate that in my opinion is just a way of telling something is not right. Although, when working with a team, it is more convenient convention over configuration. In these cases, tools like yeoman subgenerators can make the development quicker and help junior devs to understand the best practices to follow within a company.
In summary, I would use Yeoman for several reasons:
- Learn about new technologies. Chances are an expert or really advanced programmer wrote a generator for it.
- In similar line to the previous point: learn best practices
- Code your own generator to make easier conventions you have within your team. Boilerplate code is a sign you will spend unnecessary time.
- Transfer knowledge between a team. Subgenerators are a good way to have someone start on a repository, project or even company.