DEV Community

Cover image for VSCode Snippet for Reducing Boilerplate Memorization in Elixir
Nyoman Abiwinanda
Nyoman Abiwinanda

Posted on

VSCode Snippet for Reducing Boilerplate Memorization in Elixir

If you have been writing software in Elixir for quite some time, you might feel that Elixir code can feel like it has a lot of boilerplates or configurations code. Elixir is one of the most fun programming languages I have ever used! And I wish I could use it for all of my software projects but to think that I could just rely on Elixir to do all of my projects is kind of naive for a software developer. I have been building software in many programming languages throughout my software development career and when I found myself switching between these languages, I often forgot the boilerplates or configurations code that exist in Elixir.

I have tried to anticipate this by creating sample projects so the next time I need to write code in Elixir (such as GenServer or GenStage code) I could just copy-paste from them. Initially, I thought this solution is enough however when I found myself needing to open other projects just to copy-paste boilerplates or configurations code that I forgot, it kind of lowered my mood to code a little bit. Have you experienced this as well?

In order to solve this simple issue yet impacting my coding productivity significantly, I decided to create my own snippet to assist me to code in Elixir that could reduce the need for me to memorize these boilerplates or configurations.

The Snippets

The snippets that I created are as follow:

genserver

Image description

genstage.producer

Image description

genstage.consumer

Image description

genstage.producerconsumer

Image description

Notice that VSCode is quite clever in that you don't have to type the complete snippet for it to show the autocomplete.

GitHub Repo

If you found the snippet to be useful and perhaps can help you in becoming more productive as well, feel free to find and use the snippet definition in this GitHub Repo. You might not need all the code that is generated from the snippet so feel free to remove some of them once generated.

For now, the snippets could help in generating boiler plates when creating GenServer and GenStage code however other elixir modules such as Supervisor, ConsumerSupervisor, Broadway, etc have their own boiler plates as well hence I am definitely going to add more snippets in the near future. If you think you have some ideas to improve them, you are welcomed to add more snippets or modify them :).

Top comments (0)