Unlocking Speed and Power: Migrating from Laravel to Golang for Developers
I had been working with Laravel, a robust PHP framework, for over 10 years and it had served me well. Like many other developers I've collaborated with, I, too, have grown accustomed to its quirks and learned to overlook its shortcomings. In some instances, I've even developed my own packages to address its limitations. Nonetheless, I've never ceased my search for a superior alternative, but I've found that nothing has quite lived up to my expectations for a suitable replacement. Golang piqued my interest as a potential web development language since its initial launch, yet during my initial encounters, it was still a relatively young language. It wasn't until 2019 that I revisited Golang, and after careful consideration, I made the decision to embrace it as my next web development language.
Why Moving from Laravel to Golang
Laravel is an all-inclusive, comprehensive and very bloated framework. It tries to integrate a wide array of functionalities, including database access, queuing systems, HTTP routing, session management, authentication mechanisms, dependency injection and more. Nonetheless, Laravel is over bloated. For instance, it heavily relies on various external packages, leading to an accumulation of over 18,000 files within your Composer folder. Laravel exhibits multiple inconsistencies that become apparent when transitioning between different versions. The technical decisions in Laravel are very questionable and can be perceived as somewhat authoritative, often urging the community to conform in order to be able to migrate to the latest version. Opting not to migrate to the latest Laravel version always has dire consequences. Your application finds itself unsupported, eventually running out of crucial security updates and support.
Golang resides on the opposite end of the spectrum, offering the means to perform tasks with utmost precision. It results in a single, streamlined executable, making deployment and monitoring remarkably straightforward. Cross-platform compatibility seamlessly falls into place. Moreover, the language incorporates inherent formatting, and transitioning to the next version is as smooth as a leisurely stroll in the park.
Trying Out Rust First
During my assessment of various programming languages, I decided to explore Rust. Both languages seemed very similar at first. The development experience was relatively straightforward; however, I encountered a few issues that led me to conclude that Rust wasn't the right fit for my needs.
Letting Go of Frameworks
When transitioning from a framework like Laravel, the initial impulse is often to gravitate towards something similar. In my case, I started my Golang journey with Beego. Beego is a fantastic framework with many features pre-packaged, much like Laravel. However, it shares Laravel's opinionated nature and hides many of its implementations beneath the surface. While there was nothing inherently wrong with it, I yearned for a deeper understanding and full control over my project's workings, which Beego didn't quite offer.
My second attempt led me to Fiber. I chose it because it positioned itself as a slim and speedy Golang framework akin to Express. Yet, similar to Beego, it also carried a significant degree of opinionation. Additionally, it didn't quite align with Golang's idiomatic style, and it pushed several libraries onto its users, which felt somewhat awkward.
In the end, I decided to take the plunge and embrace Golang without a framework. All I truly needed was a well-designed, idiomatic router library. That's when I discovered Chi, and it turned out to be a perfect fit. Chi provided the flexibility and control I craved, making it a seamless and efficient companion for my Golang web development journey.
Finding the Correct Libraries
Transitioning to Golang was a bit of a challenging experience. I soon realized that Golang's library ecosystem, particularly in the realm of web development, didn't offer the same extensive set of pre-built features and utilities that I was accustomed to in languages like PHP. In fact, even the standard library in Golang appeared to lag behind PHP's feature-rich standard library. Simple tasks that you often take for granted in web development, such as stripping tags, URL escaping, and similar functionalities, were conspicuously absent.
However, Golang's strength lies in its simplicity and the ability to craft your own modules. This was precisely the path I chose to follow. Determined to overcome these limitations, I embarked on a journey of building my own utility library. Slowly but by bit it became a comprehensive collection of the tools and functions I needed for web development in Golang. By crafting these modules from scratch, I could tailor them to my exact requirements and preferences, ensuring that my Golang projects had the capabilities I needed to deliver exceptional results. In the process, I not only met the challenges head-on but also gained a deeper understanding of Golang's flexibility and extensibility, which allowed me to shape the language to meet my specific needs.
Getting Rid of Templates
Golang's standard library does include a templating library, but using it feels like a massive pain. It's so frustrating working with it, which is the reason why there is a proliferation of third-party libraries attempting to fill this gap in the Golang ecosystem. However, the interesting thing to note is that many of these third-party libraries tend to adopt a template rendering approach akin to what you'd find in other popular frameworks such as Laravel or Django and also come short of expectations.
Web Development with HTMX
Transitioning from Laravel to Golang was definitely the right journey for my web development endeavors. It was a decision that not only met but exceeded my expectations. With Golang, I found a world where the quirks and idiosyncrasies of Laravel were a thing of the past, and only the finest aspects of web development remained.