Developers at Google recently launched a new experimental feature called Macros which adds support for static meta-programming to the Dart language. From their website:
A Dart macro is a user-definable piece of code that takes in other code as parameters and operates on it in real-time to create, modify, or add declarations.
I've spent the last few days experimenting with this new feature and I'm super pumped.
Why I'm Pumped?
My usual development stack is as follows:
- Postgres as my database
- Python (specifically Flask) as my back-end framework
- Dart (specifically Flutter) as my front-end framework.
And my usual workflow for implementing a new feature usually goes like this:
Plan the database changes
Implement the model in Python
Create the API
Implement the model and views in Flutter
Integrate the API in Flutter
While my current development stack is powerful and I use it in 99% of my projects, there's one major drawback I've experienced.
Development is not always that straightforward
The Challenge of Context Switching
I can recall many instances where it's necessary to context switch between Flutter development and Python development, but, this isn't always as straightforward as it seems. I often find myself writing Pythonic syntax in my Dart files and Dart syntax in my Python files only to backspace it all and rewrite lines of code in their proper syntax. This is where I see
Macros increasing the efficiency of my development.
How can macros make me a better developer?
If context switching is error-prone and it's one of the reasons why I'm not as efficient as I can be, then I can reasonably conclude that if I don't have to context switch, my development flow will be faster.
Currently, many developers use the Dart programming language through the Flutter framework to develop Android and iOS mobile apps, web apps, and Linux, Windows, and MacOS Desktop apps but, not many use it for server-side Programming.
I've spent the last week researching Dart in the context of Server Side programming and I've discovered many resources such as Serverpod and Dart Frog. But I've also seen many projects that are no longer maintained such as Angel, and DartORM
The Dart ecosystem has many resources on how to use Dart for CLI and Server Apps that use packages that are maintained by the Dart Team. So, I've decided that if I am going to change my entire stack to be purely Dart, I'd want to use resources that are actively maintained or resources that I can easily maintain.
And, what better way of acquiring a resource that's easy to maintain than writing it from scratch? I've decided that I'd test out the power of Macros to see what it's truly capable of by writing my own ORM for Dart!