Friday, January 17, 2025

Pushed First Code Commits of Frontend Work Done with Opal Ruby + Glimmer DSL for Web to My Job's Rails Web App Repo

I'm happy to report that I officially pushed the first Opal Ruby + Glimmer DSL for Web code commits to my job's Rails repo in the Admin UI last week. It is just amazing how Glimmer components written in Ruby to replace React components are way simpler and smaller! It's not even close! My productivity definitely feels double at least while producing about half the code. This is so exciting! It reminds me of the early fun days of discovering Ruby, but on the Frontend! There is so much potential and so many possibilities. It is super exciting to discover new patterns and best practices. Ruby creates so much programmer happiness compared to JavaScript! I literally volunteered extra time after work last week to refactor/fine-tune some Frontend components in Opal Ruby because it is SO MUCH FUN!!!! React's JavaScript code looks like ugly over-engineered over-complicated dinosaur code nonsense by comparison, it feels like writing Glimmer Ruby code is like waking up from a bad spell. I literally was so stupid to use React or any JS tech in the past 10 years when Opal Ruby was available (by the way, it has won a Fukuoka Ruby 2023 award). I would have never overcome my stupidity if I acted like I'm too important or too insecure to admit stupidity or if I lied to myself about it just because "an important person" at "a large rich important corp" said "React.js is good" without questioning it with my own brain, which is why I'm admitting it now. Using Ruby in the Frontend feels like that's the way things should have been 10 years ago if Rails was more creative and didn't bail out on us, Rubyists, by adding Webpacker temporarily for a number of releases instead of adding Opal Ruby as a default. Thankfully, Glimmer DSL for Web comes to the rescue for Frontend Development in Rails web applications. I am literally operating on a whole other level with it over everyone in the Rails community who are using JavaScript right now!

By the way, as far as how I convinced my bosses to use Opal Ruby + Glimmer DSL for Web at work, I did the following:

  • During off-work-hours (one weekend, mostly in one day), I built a work app POC (Proof Of Concept) of an Opal Ruby + Glimmer DSL for Web SPA (Single Page Application) by rewriting a sophisticated React page component that had a lot of interaction going on. I proved to myself first that Ruby code is so much simpler and better than JavaScript code.
  • As a Senior Software Engineer, I scheduled a short 15-minute demo with my teammates and the CTO to demonstrate a new better way of developing Frontends for our Rails web application that could cut down 12 months of Frontend Development work a year into 6 months. That huge difference in productivity got their attention. I prepared well for the demo, including anticipating questions for the Q&A period. When I did the demo, I made sure to show the Frontend code improvements using Ruby right away and to keep the demo short, like no more than 15 minutes. I had about 15 more minutes of Q&A afterwards because everyone was so excited to ask questions that we lengthened the meeting, and I made sure to provide good answers and not to cop out or naively fall in the trap of accepting negative narratives. I also provided a phased plan for how to implement Opal Ruby + Glimmer DSL for Web gradually in the codebase to manage risk in a Lean/Agile iterative incremental way by starting usage in the internal-facing Admin UI, and then 6 months later, using in the public UI in low-risk features, and 6 months after that, using in the public UI in high-risk features, and 6 months after that, rewriting all React JavaScript code in Glimmer Ruby (the actual phased plan might end up having a shorter timeline for transitions than that, but I had to provide the least risky plan first).
  • I scheduled another demo with the Director of Engineering after all my coworkers and the CTO told me they definitely thought Opal Ruby + Glimmer DSL for Web were interesting technologies. He asked me to prepare for him a comparison between the performance of Glimmer DSL for Web vs React. So, I used the POC that I built as a benchmark. It was to my huge delight that it ran ~33% faster in Glimmer Ruby than the React JavaScript version. After I gave the demo (including a performance sub-demo), the Director of Engineering was very impressed and told me he was OK with me integrating Opal Ruby + Glimmer DSL for Web in the week between the holidays and the start of the new year's work when employees get back from their planned vacations. That was last week.

By the way, my work app is not a vanilla Rails app as we are using Webpack using JS bundling for Rails, so I was able to surmount the challenge of integrating Opal with Webpack and finish the integration in about 1 day only. The deployed app loads pages instantly in our cloud Staging environment whether the page assets are JS files generated by Opal or Webpack, which is amazing! Ruby performance in the Frontend is absolutely good for our Rails web app even in a sophisticated SPA webpage.

Glimmer DSL for Web (open-source Ruby-in-the-Browser Web Frontend Framework) GitHub repo:

https://github.com/AndyObtiva/glimmer-dsl-web


No comments: