Thursday, April 23, 2015

Understanding the language in it's own way.

It's been a while since i posted here, I got a little free time on my hands courtesy of waiting on comments on a pull request.
A few days ago i really wanted to develop a very quick rest application. I have been writing a lot of java services of late which are consumed by rest applications. Despite my tests around it on the java level I wanted to ensure if there was a quick fire way to test it from the rest layer without going into the hassle of building a whole array of projects to test what i want.
I was evaluating a couple of options given my laziness. One was to use sinatra, second was to use the dropwizard-core library. I have been reading about the waves its generating recently also instilled further into my curiosity. I tried setting up a demo project and it seemed seamless but still decided to use Sinatra given my earlier familiarity with it.
A little intro about Sinatra its a DSL for developing web applications in Ruby with minimal effort. It's a direct quote from their github repo and my stress will be on the minimal effort. It really is that minimal if you're developing a rest application you will have to mash up the get,post, put or delete logic in one spot in a ruby file and import sinatra as dependency and when you run the ruby file you will have it running your endpoint locally. It really is that simple.
I did run into a little snag which costed me a good hour to troubleshoot though. It was my mistake combined with the super dynamic aspect of Ruby which made it harder for me to catch it which was really the point of this post.
The gist of the mistake i did was I had a collection of Strings in a constructor and then I had a collection of Objects but when i initialized the constructor in one of my workflows I was passing in a collection of Objects in place of collection of strings it was supposed to take. In Java the beauty is it would've shown me a compile error then and there but not in Ruby though where most of the conversions in my understanding happens on the runtime which is where it was freaking out saying incorrect number of arguments received.
Another major part of the problem when i thought a lot about it stemmed from the concept of me writing Ruby code like a java programmer, thats because I am still not a seasoned ruby coder. It was a really icky mistake which could've been avoided in the compile time itself but then again given the awesomeness of sinatra i was able to write an application which i used to test my workflow very very quickly.
I am also not trying to compare Ruby or Java in this post they are both awesome in their own unique way. As much as how I love java it would've taken at-least triple the time it took for me to set this project in Sinatra. This post is on the concept of trying to give me the idea of trying to understand the language in its own way rather than trying to simulate one language in terms of another.
oh well my pull request comments demand more attention now. Until next time!!