DEV Community

Cover image for Learning Ruby after Suffering with Visual Basic as my Primary Backend Language for Years
andyreadpnw
andyreadpnw

Posted on • Edited on

Learning Ruby after Suffering with Visual Basic as my Primary Backend Language for Years

I can count on more than one hand the instances where someone literally laughed when I mentioned my preferred (and only) programming language was Visual Basic. Some people had not even heard the words Visual Basic before. I had used VB as the basis for all of my databases and automation up until recently in my career in ecommerce at Eddie Bauer and working for Microsoft as a contractor. It made me think I was somehow patching together applications that were fundamentally flawed and all their components obsolete. I was not really coding the ‘right’ way. Well I was right in a way (my coding conventions, commenting, and structuring probably left those who took over my applications to tear their hair out), my self-guided attempt doesn’t look that amateur in hindsight and allowed me to build multiple helpful applications. VB got the job done when I needed it. However, my introduction to Ruby has shown me the benefits of using a more tailored and powerful language to create a finished product. Now that I have some experience with Ruby after VB, I wanted to compare the languages briefly and identify a few things that Ruby does well as compared to VB.

Foremost, Ruby is a great language for ease of understanding and the simplicity of the syntax allows fast comprehension of how the program is interacting with other classes and variables. Ruby is written almost as if it is English; I want to look through my hash and find items that match? Simply write “Items.all.select{|item|item.id == input.id}”. VBA by contrast has a number of methods and database specific actions that are unique to language. Unless you have experience using these specific methods, you will probably have to constantly reference the documentation (like I did) or check Stack Overflow to make sure you are using the accurate VB-specific operation. For instance, the two code snippets below accomplish the exact same function. That is: check my database that houses company promotion information and return all those records that match the offer amount I specified.

This is how that operation is done in Ruby:

Ruby Snippet

And this is how that operation is done using VBA:

VB Snippet

That is a big difference, right? Perhaps there is a reason VB is the 3rd most disliked language behind Perl and Delphi according to an aggregation of Stack Overflow developer stories.

The other thing I would like to point out is Ruby is much less strict with variable declarations and streamlines the constructions of classes and models. Ruby is very intuitive in how the user defines and accesses the elements and class models whereas VB requires declarations of variables everywhere we want to preform actions on those objects. Defining global variables in VB is required outside of the functions and methods so the class is cluttered with a long list of declared variables that apply to the many methods one can expect to build. Ruby is much cleaner and allows syntax to keep track of local, instance, and global variables even within our methods.

Perhaps the most significant benefit of Ruby I have noticed are the libraries and Gems that allow additional functionality to users. Suppose you want to have an authentication function in your program so you don't always need to write one, you can get it in form of a gem. The Ruby community is significantly more active and up to date than VB that has a tiny user-base from a codebase that is 30 years old. In this way Ruby allows for great compartmentalization of plug-in functionality that is readily available.

Additionally, the testing dynamic in Ruby is infinitely more defined in Ruby than it is in VB. Apparently, test-driven-development is possible in VB, but it requires workarounds and add-ins and is certainly not as widely understood by the userbase as testing is to Ruby. Ruby has rspec tests that are built into the language and allow users to clearly define how they expect their code to work and see if what they wrote matches that expectation.

Despite my preference for Ruby as a language, I can’t be too hard on VBA though as it is very good in certain use-cases. VBA is native to all the Microsoft Office Suite and already contains all the libraries we need. It's a godsend to be able to automate repetitive Excel tasks and distribute a working template or email system data daily or create a UI over a SQL database for a team that doesn’t know SQL. I would greatly prefer this instead of creating documentation the end user won't end up reading anyway.

Many of the applications I built are still in use and solved critical business needs, I just wish I would have pursued learning another language sooner! It was the only language in my toolbox for 6 years and my introduction to Ruby opened my eyes to the limitations of VB. Then again, there is always a better way to do things and you can’t know there is a better way until you try. I look forward to finding another language that I like even better than Ruby.

Top comments (0)