DEV Community

Stefan Dorresteijn
Stefan Dorresteijn

Posted on • Updated on

My search for supremacy

Internally, a struggle between good and evil is never ending. Externally, I smile, nod, and write functional code.

When I decided I wanted to learn how to make websites, I went to a friend for help. He told me I should learn PHP so I bought a big fat PHP book, read the first 20 pages and then decided I knew enough to get started. My very first project was my own personal website. I started by taking an HTML template a friend of mine created and turning it into a database-driven blog. This entire blog consisted of two files. index.php which connected to my database, queried it for blog posts, formatted those blogposts and listed them and post.php, which connected to my database, queried it for a single blog post, formatted the blog post and allowed a user to read said blog post.

From behind my keyboard I can hear a million developers sigh and groan. Don’t worry, in the eleven years since then I've learned a lot. I now understand MVC and MVVM models. I understand the importance of file structures and how to write proper routing but the biggest thing I've learned, the thing that changed everything was Object Oriented Programming.

Seriously OO

After a short stint with PHP and a passionate but short relationship with C#, I found my one true love; Ruby (on Rails). This was my first introduction to full on Object Oriented Programming and I fell in love immediately. To me, writing applications in OO languages feels like extending the analogue world into the digital space. The world is Object Oriented and once you subscribe to that way of thinking, writing proper OO code becomes easy and natural. For a year and a half I did nothing but write Ruby code. Every project, every application, every line of code was done with Ruby on Rails.

As a framework, Ruby on Rails has its disadvantages. It’s 2017 so real time applications are becoming more popular and asynchronous functions have become the bedrock on which a lot of applications are now built. Unfortunately, Ruby on Rails isn’t great for either of these concepts. Don’t get me wrong, RoR has improved but when I was asked to make a sports betting website (which needs to be almost entirely real time), I made the decision to use JavaScript (on NodeJS) instead of Ruby (on Rails.)

Back to JavaScript

When I code in Ruby, I swear in English. When I code in JavaScript, I swear in Ruby.

Saying I don’t like the JavaScript syntax or code standards is an understatement but it has great advantages too. Completely built for asynchronous function calls and with very easy real-time communication implementations, JavaScript is an incredibly useful language for projects such as the one we were going to be working on. I hired a few developers — asking them all if they preferred Object Oriented or Functional Programming to understand what kind of experience they’d had — and we started developing.

Initially, every line of code I wrote felt inefficient. Leaving Ruby behind meant leaving behind the comfort and ease of coding that drew me to Ruby in the first place. As the project grew and we had more types of data to handle, I started to long for the Object Oriented way of thinking, and more than that, for the relational database that’s so common in Ruby projects and so uncommon in JavaScript projects. Having to do 4 or 5 queries to render a page with fully relational data seemed unnecessarily slow to me and while I knew better, I attempted to turn JavaScript into an Object Oriented language, with relational data being generated at the model level.

At first, my solution felt great. I was able to write JavaScript as if it were Ruby, my data was relational and I didn’t have to write multiple queries for it. However, it didn’t take long for JavaScript to hit back. The functional-to-object-oriented-hack I made was slow and it was affecting our application. I realised I had to accept I wasn’t using Ruby anymore, refactored our application and went back to functional programming.

We finished our project's MVP, refactored a few more times and found a reasonably comfortable way of writing code. I was getting used to the functional programming way of like but much like getting used to wearing glasses, I wanted to see 20/20 again.

New beginnings

My real-time project has come to an end. I have seen the powers that JavaScript can give a developer and I have accepted that some languages work better as functional programming languages. On the other hand, I still believe in the power of object oriented programming and prefer it over functional programming in most situations. Now I’m offered new projects and am forced to find a language that fits the problem set. I could choose to use JavaScript when I need asynchronous functionality and real-time communication. Then when I’m building larger applications with relational data, Ruby can be my go to. It's never bad to have many tools in your arsenal but I know myself. I will keep searching for the one ring to rule them all. The one language that is easy to write, object oriented, does real-time and async quickly and easily and above all, doesn't have semi colons;

The search for supremacy is never ending. The answer is out there somewhere.

Top comments (10)

Collapse
 
andy profile image
Andy Zhao (he/him)

doesn't have semi colons;

Ha! Nice joke at the end there. Made me laugh :)

Thankfully, my experience has been that Rails and Javascript play pretty nicely with each other. For your next app, is that something you would consider? A Rails backend and a JS frontend has worked decently for me, but I've also never built a huge app before.

Collapse
 
stefandorresteijn profile image
Stefan Dorresteijn

Thanks! Yes, I think building a central API and building distributed frontend applications is an innovation we really needed. Almost every website I build now has a JavaScript frontend using a framework like React or Vue (and recently I've added GraphQL as well.)

The problem still lies with the choice between Rails and NodeJS for me in most projects and lately it's come down to the special functionality I need (real-time, async, etc.), I would just prefer a language that does all of that. Elixir comes close but is still very functional.

Collapse
 
andy profile image
Andy Zhao (he/him)

Appreciate the quick response! I've heard really good things about Elixir from a few people, but still don't know much about it.

Also, thanks for the clarification about your choice. That makes a whole lot more sense now. Since you mentioned it, I think Rails is headed toward more async and real-time features now with Rails 5, ActionCable, and just more JavaScript support. Do you think it'll "catch up" to a point where those features would match NodeJS?

Thread Thread
 
stefandorresteijn profile image
Stefan Dorresteijn

Yeah, I'm trying to learn Elixir during my free time but haven't gotten around to using it in a real project yet.

Yeah, Rails will improve but NodeJS is non-blocking in its very core so it's very much built for async functionality. I'm not sure Rails will ever catch up to NodeJS, especially with how many people are moving towards NodeJS (and away from Rails) lately but we'll see. I don't think the OOP crowd has the majority right now in web development either so we're really up against it.

Collapse
 
kspeakman profile image
Kasey Speakman

I've found that nearly all languages bring something to the table that grows me as a developer. Even PHP (also my first professional experience), which is universal and easy to get started.

A side note. JavaScript has a very limited picture of Functional Programming. The main thing it does have is functions as first-class citizens, which goes a long way. But it is worth checking out functional-first languages to gain even more problem-solving methods.

Collapse
 
stefandorresteijn profile image
Stefan Dorresteijn

Two strong points. Every language I learned has taught me something, even the languages I don't use anymore (read: PHP & C#). I also think functional programming can teach you new problem solving methods, I'm just not convinced of its strength in large projects.

Collapse
 
kspeakman profile image
Kasey Speakman • Edited

Hmm, that's interesting. Here are some examples of that (functional languages in the large) if you haven't seen it.

  • Elixir on the Erlang runtime
  • F# on the .NET runtime
  • Scala on the JVM

Now if you were talking about JavaScript for large projects, I would agree with you, but I would not characterize JS as a Functional Programming language despite having some elements of one. Also it is dynamic, which is often looked on as harder to manage for large projects. Maybe for "microservice" based projects it is not hard to use a dynamic language like Clojure, since the responsibility of each piece is small.

Thread Thread
 
stefandorresteijn profile image
Stefan Dorresteijn

I'm actually learning Elixir right now in an attempt to prove myself wrong when it comes to functional languages. It's been a blast so far.

Maybe JavaScript itself isn't a Functional Programming language per se but the majority of JS developers I've worked with - and speak to - use it as such. As far as dynamic languages goes, I agree that they're harder to manage on large projects.

I think it comes down to the fact that I like very strict rules/standards in software development, which JS (especially with Mongo) doesn't have. RoR is famous for having developers abide by the Rails way which feels like the right way to guarantee quality in a language/framework.

Collapse
 
richjdsmith profile image
Rich Smith • Edited

Loved the dig on the second last paragraph; 😄

Have you checked out Elixir/Phoenix? It's an easy move to go to from a ruby background. It's become my go-to language.

Collapse
 
stefandorresteijn profile image
Stefan Dorresteijn

Yeah, that's what I'm trying to learn right now, hoping to write on it soon!