Day 01 - Learning by starting to blog...?

Day 01 - Learning by starting to blog...?

The journey of becoming a software developer

·

4 min read

Hello theređź‘‹, welcome to my first blog here on Hashnode. My name is Terry.

I spent 7 years working as a graphic designer but now I am going to change my career to be a software engineer by joining a dev Bootcamp from Makers which is a coding academy based in London.

This series is about my coding journey, from a total beginner to a software engineer, with written records of my ups and downs during my learning.


Why do I start blogging?

Since I joint a 16-week dev Bootcamp in Makers, coding with Ruby has become a part of my daily life. Searching answers from Google and checking tutorials on Youtube are my main ways to solve coding problems.

During the process, I found that some answers were actually from someone's blog, surprisingly with a well-documented explanation and also coding examples. This made me start to think that blogging might be an important tool for programmers to share their knowledge with the world and learn from each other.

I further looked for videos explaining to me why developers need blogging and I found Programmers That Don't Blog Should Start Right Now from Adrian Twarog.

I really like the idea of being a part of the developer community by sharing articles on social media like this one. And I think this is also a good opportunity to document my coding journey as well. That's why I am here to start writing my first post.

And hopefully, I will share some tips and tricks on Ruby or Javascript here in the near future to contribute back to this community.


What did I learn today?

Okay, let's talk about what I learnt from Ruby today.

Codewars

The main focus today is on Codewars ranking up kyu by solving kata.

Sum of Intervals

The most painful one for me is the sum of Intervals which is a 4-kyu kata, a bit challenging for a 6-kyu programmer like myself. After working for an hour, I still couldn't solve the problem so decided to unlock the solution with the curiosity of learning.

The solution is easier than I thought but the logic behind is a bit advanced. Here is the part I admire the most.

def sum_of_intervals(arr)
    s,top = 0, nil
    for a,b in arr.sort do
        # Checking if previous top is smaller than current bottom
        # this line is awesome!
        top = a if top.nil? || top < a
        if b > top
            # adding up the size of the array
            s  += b-top
            # Assigning current top value to the variable 'top'
            top = b
        end
    end
    return s
end

By tracking and moving the value top, the code is capable of adding up the size of arrays without adding repeated numbers. This solution is so simple and clever!

Pagination Helper

This task asked me to finish a Class PaginationHelper which is a utility class helpful for querying paging information related to an array.

This time, I figured the solution out by myself without revealing the answer.

I did some research on how to split an array into small chunks of arrays. And here is my final answer.


class PaginationHelper

  def initialize(collection, items_per_page)
    @collection = collection
    @page_count = (item_count.to_f / items_per_page.to_f).ceil
    @new_collection = Array.new(@page_count).map.with_index {|item, i| collection[i*items_per_page...(i+1)*items_per_page]}
  end
  # codes continue....
end

This kata taught me a few things:

  1. ceil() - I can't use it without turning item_count to float by using to_f

  2. map() - by using Array.new(3) with map(), I can loop through and return a new array with the correct values

  3. with_index - adding index to the method map()


Plan for tomorrow

Tomorrow will be the last day before Christmas break. Here is my plan for tomorrow:

  • Start building a CV on Github with the template given by Makers

  • Learn rspec which is a TDD library for Ruby

  • Create another blog post explaining 'how to remove whitespaces in Ruby'

  • And... blogging my dev journey on Hashnode of course!

Did you find this article valuable?

Support Terry Cheng by becoming a sponsor. Any amount is appreciated!

Â