The other class I’m enrolled in this term, alongside Capstone, is Programming Language Fundamentals. We’ve been learning about a mix of programming history, language design, syntax/grammar rules, and various programming paradigms. One of the most well-known paradigms among these is Object-Oriented Programming. The concepts that make OOP stand out among the pack are its use of classes, data abstraction, encapsulation, inheritance/composition, and polymorphism (to name only a few). Most of my experience as a programmer has involved Python, JavaScript, and Bash scripting. Python supports object-oriented principles but isn’t a pure object-oriented language. JavaScript is similar but tends to drift even further away from pure OOP when looking at a language like Java or Ruby.
enter: ruby
Ruby is a pure object-oriented language that is heavily class-based. I recently learned and used Ruby when implementing the game “Rock, Paper, Scissors, Lizard, Spock” for a Lab in Programming Language Fundamentals. The object was to design parent classes for various Elements, Players, and History, and to manage how the children of these classes interact with each other to create the logical relationships that make up the game. The experience was actually really fun. Being constrained to pure OOP made the development process easier and clearer than if I was simply given a blank canvas and the option to use another language (say Python or JavaScript) with a mixed approach. It gave me the itch to be more “OOP-minded” in the other parts of my life: namely at work and in the Capstone class.
classes outside of “classes”…
Over the last month or so at work I’ve been using Python to create a wrapper to automate a benchmark that simulates Java application performance called SPECjbb. One of the recent design issues I was faced with was making the almost innumerable amount of flags configurable in the Python script. Some of the flags are boolean and include a certain prefix to indicate this, while others are more like key/value pairs. Some serve a purpose for the benchmark while others are specific to how Java is run from the command line for the benchmark. These are just a few of the design issues that stem from these options, there are other internal requirements we have that constrain how we use and process these flags that I won’t expand on here.
After being stuck for a number of days, this recent use of Ruby in my other class inspired me to approach the problem from a different angle. What if the different flags were categorized as data members of a larger abstract class? After traveling down that road for a few minutes I realized that I could create methods that would successfully transform the flags from their raw/default state, and return them in a string format for use on the command line. By having different methods that go with different data members, I no longer had to worry about the fact that some flags were written and parsed differently from others.
OOP gives you wings™
This gave me an immense amount of freedom to creatively attack the problem in a number of ways, rather than feeling like I was stuck solving it in a more constrained manner. Up until now, I haven’t yet had to implement any class-based solutions at this internship. Most of the work has involved making use of objects whose classes and methods are already defined, so my code has felt largely “script-like”.
It was very satisfying to solve the problem with an abstract class, and it felt like I had turned a corner into a new realm of possibility with my programming and problem-solving skills. One of my biggest gripes about how we often learn about OOP is that the programming assignments used to teach it are often trivial games or employee/business back-end simulation programs, and it never quite feels like I can see the connection from these examples to using the powerful concepts of OOP out in the real world.
I’m excited to have been inspired by Ruby and OOP to implement a unique solution in a production-level codebase. I’m glad this is one more “notch” in my proverbial toolbelt, and I will be looking for more creative/class-based solutions in my future programming efforts.