In lieu of the new languages that sprout out ever so often, I’ve created a little repository of source code that’d allow me to take well formed concepts and ideas to see how it’d be represented in another language while taking advantage of the capabilities of said language. The languages I want to tackle are listed on its README and I’ll try to update this thing at most weekly so that I can experiment with just the basis of languages.
The reason why I didn’t want to pick up a whole big process for this is largely because this is like a notebook for me. I think I’ll be very liberal with comments and end up revisiting some of the examples I use there so I can see how my understanding of said language changes over time. A coding journal written in code.
For example, I’d start off with a simple math problem that’s typically used to explain recursion in programming, a Fibonacci number generator. For completeness, let’s define the expression here using the recurrence relation:
Simple, no? We’ll make use of the benchmarking library in Ruby so that we can generate timestamps for every high-level execution of the Fibonacci function. The code for this would look like the following:
The full source can be examined here1. The output for the above source file would look something like the following2:
With one file, I went over a few things that’d help when writing larger programs with Ruby. Timing, string manipulation, math and a logic tree that one might take when going about things in their programming adventures.
Whilst searching for some information on Go and Ruby, I ran across Rosetta Code. This actually does what I would have wanted but it’s way more concise than I’d care for. And I didn’t do it; writing the code myself and testing it against a premise allows for self learning. Copy pasta can’t save you all of the time!