A tale of knowledge building

A tale of knowledge building

Sharing my experience when learning something new

I love to learn and how we build up knowledge.

Also, I love to apply my knowledge somewhere, so here's a story about this.

Disclaimer

This post doesn't try to teach about the technologies it mentions but to describe a recent experience and highlight my thought process on a specific topic. If you get curious about the topic, the most relevant links are in the Resources section at the end of this article.

Building knowledge

Some time ago, Jason Lengstorf did a show with Laurie Barth about Babel plugins. I liked that show a lot, and it led me to Nicolò Ribaudo's talk about Babel plugins.

I had a look at creating Babel plugins in the past but didn't get it well enough. These two resources cleared a lot of things for me!

Nicolò's talk led me to Kent C. Dodds's babel-plugin-macros, which "defines a standard interface for libraries that want to use compile-time code transformation".

I had seen the plugin before but didn't quite understand it.

Now, I had more knowledge about it so I had to apply this knowledge.

Applying knowledge

Context

super-expressive is a library to create Regular Expressions (RegExp) in almost natural language. It's useful, simple and well-documented. One downside it's that it's a runtime library, something else to add to our bundle.

I saw an issue on its repository asking if there was a way to generate the RegExp at build time - link here - and I thought: "A Babel macro, maybe?", but I didn't understand them well enough back then. When I learned more about Babel plugins as explained before, I remembered about this issue and decided to give it a try.

The process

Those videos gave me a base for the task but I needed more sources to achieve it, so I read a lot of source code for other libraries built with babel-plugin-macros, read the plugin's authoring documentation and Jamie Kyle's Babel Handbook.

After a couple of weeks of playing around with the idea and learning much more about Babel plugins in the process, I released super-expressive.macro - a macro to generate Regular Expressions (RegExp) at build-time with super-expressive.

It's far from perfect, I'm not 100% satisfied with it, but it's an actual result of the things I learned! For me, that's the best way to persist any knowledge: building something! This leads us to learn more than from the resources we consumed before. In my case, I went beyond those videos.

Extending knowledge

After releasing super-expressive.macro, I was thinking about where else I could apply this knowledge. To be honest, I'm not using the macro, I don't know if anyone will ever use it, so I wanted to apply the knowledge to something I use every day.

That's when I realised that to create ESLint rules, we use a similar approach to Babel plugins.

At Kindred Group, where I currently work, we have an internal ESLint config and there were a few custom rules we could create to help our teams in some cases. At that point, there was only documentation suggesting X or Y, nothing integrated into our workflow.

I decided to create these rules and learned even more in the process. Once again, I was reading the source code of ESLint plugins out there to get to the result I was aiming for and, fortunately, I did! We have a set of rules now our teams can benefit from every day. 🎉

I mentioned some of the plugins I went through in the #8 edition of my newsletter.

Reflecting on the journey

As I'm writing this, I don't have other places where to apply this knowledge. Maybe I'll move to the next thing to learn, maybe I'll have more ideas for macros or ESLint rules, I'll see.

Although this post highlights the happy path and results, of course, I had bumps along the way.

I thought about giving up on super-expressive.macro when I couldn't get anything to work with the things I learned from the videos. "No one needs this, why bother and waste my time?"

But I've learned over the years that persistence is very important - in and outside our job. Just step away from the problem for some time, return with a clear mind and give it another try.

It works every time! Plus:

  • "If you're learning, no time is wasted."
  • "Abandoning something before we learn anything doesn't do anyone any good. It actually makes things worse because we feel like quitters."
  • "Every new project furthers our discovery process."

The quotes above are from Jason's blog post about "wasting time". I read it while writing this post and it's a perfect fit for my reflection above. Give it a read.

Resources

Wrapping up

I hope you enjoyed this post and it's helped you in any way. It's very different from anything I've written before but I felt like I needed to write it.

Let me know your thoughts in the comments.

Subscribe to my newsletter and follow me for more.