I spent most of January working on exercism challenges and refamiliarizing myself with Rails. I haven’t been able to pair program with other people yet and online exercises have been the only way I’ve gotten feedback for the programs I’ve written. It’s been a good way to learn more about design patterns and subtleties in the Ruby language. Out of all the exercises there, I enjoyed the one about Binary Search Trees the most. Another user on the site turned me towards using the Null Object Pattern and my research into the topic led me to an article that illustrated how it could be used in Ruby. In the end, I ended up with code that looked like this:
class Bst
attr_accessor :left, :right, :data
def initialize(data)
@data = data
@left = NullObject.new
@right = NullObject.new
end
def insert(number)
if number > @data
in_right(number)
elsif number <= @data
in_left(number)
end
end
def each(&block)
left.each(&block)
block.call(data)
right.each(&block)
end
private
def in_right(number)
right.insert(number) or @right = Bst.new(number)
end
def in_left(number)
left.insert(number) or @left = Bst.new(number)
end
end
class NullObject
def data
nil
end
def insert(*)
false
end
def each(*)
self
end
end
The exercism website also had challenges that involved other data structures like linked lists and matrices. I’ve been reading more and more about how to become job ready as a programmer and there have been a lot of advice on being familiar with common data structures and how to implement them as well as recognizing the Big-O complexities of different algorithms. I’ve mostly been teaching myself and I know that I need to spend time on subjects that other programmers would have been exposed to in school. I want to do my best to expose my ignorance now.
I’ve also started a membership at upcase so that I could become more familiar with the tools that Ruby on Rails developers use. I’ve learned more about how to use vim and testing use rspec/capybara. I’m amazed by how efficient I could be using while vim and how easy it could be to learn when I’m pointed in the right direction. I’ve neglected how to write my own tests in the past and I’m trying to remedy that by learning how to use the tools other developers employ. Currently, I’m also trying to learn how to use tmux in one of upcase’s new trails.