Josh Thompson     about     archive     tags

Quick Dive into React

As usual, this is a work in progress. At a high level, I’m familiarizing myself with Phoenix/Elixir, and need to sharpen my React knowledge along the way.

After working through part 1 of a slack clone in Elixir/Phoenix tutorial, I ran into some errors getting the React app up and running.

I expect errors, but don’t have enough familiarity with React to effectively debug, so I’m going to take a quick spin through the tool, see what I can quickly learn, and then debug the errors I saw.

>> Read more

Elixir/Phoenix part deux

I planned on working through this tutorial for building a slack clone, but half-way through the set-up instructions, after I installed Elixir and Phoenix, I took a long detour through the basic set-up guide. Built some custom routes, along with controllers/views/templates, etc.

I’m now a bit more comfortable with the basics of the framework and language, so I’ll now be working through the tutorial, and Rubber Duck Debugging by writing about it as I go.

This will be a bit of a work-in-progress. Onward.

>> Read more

First pass with Elixir/Phoenix

I’m digging into Elixir and Phoenix. I’m working through this tutorial to cloning Slack.

The tutorial author says

At the time of writing, I have ~1 week experience with Phoenix. Similar to Rubber Ducky Debugging, I am writing this blog post to force myself to think differently about the problems I am solving and therefore gain a better understanding of the language and framework.

Couldn’t agree more myself. This post serves as my Rubber Ducky Debugging process for getting started with Elixir/Phoenix.

Similar to the author, I come from a Ruby/Rails background, but undoubtedly less experienced than the author. So, this article will capture tidbits and pieces useful to me as I work through the tutorial.

I’m intentional in how I learn, as well as in how I ask questions, so this is just me, doing what I do, to learn things.


Installing Elixir and Phoenix

Installation is super easy.

The recommended tutorials + some clicking around was all I needed. Brew handled most of it, and elixir-lang’s installation guide pairs well with the same for phoenix

I just cd‘ed into workspace/elixir (where my otherwise homeless bits of code lives) and test-drove Phoenix’s equivalent of rails new. I’m taking a quick detour through this guide at the moment.

OK, it was more than a quick detour. The rest of this post is me familiarizing myself with the above guide. Read Elixir/Phoenix part deux for more

>> Read more

Blocks and Closures in Ruby

Continuing on from yesterday’s post about method_missing, I’m moving on to a part of Ruby’s language that has been a bit of a mystery for me for quite some time. I’m still working through Metaprogramming in Ruby.

It’s the concept of lambdas, procs, blocks, and more. I also hope to better understand closures, and perhaps even some aspects of functional programming, as I’m used to (so far) thinking in OOP approaches.

I expect my first pass to be rocky, but to also lay a foundation for better understanding later. I’m writing this out because this is how I learn.


First new term: yield. (docs)

It is always related to passing blocks around (to methods, or other blocks, procs, etc). I think lots of what we do with blocks interacts with the yield function, but it gets called behind the scenes. (Sorta how initialize calls, among other things, new)

you can call yield from inside a method to see any block passed to it. You can also call block_given? to see if there’s a block floating around anywhere.

def a_method
  return yield if block_given?
  'no block'

=> "no block"

a_method {"look at me, I'm a block"}
=> "look at me, I'm a block"

a_method do
  "i'm inside a do..end block"
=> "i'm inside a do..end block"
>> Read more

Metaprogramming in Ruby: method_missing

I’m working through Metaprogramming in Ruby

It’s a great read. There are examples in the books, but I wanted to take them out and apply them to some easy Exercisms.

I feel some disclosure may be useful. In no way, at all, should you ever implement any of the “solutions” I’m exploring here. I’m intentionally breaking things and doing them wrong to grow my understanding of how Ruby works.

If you’re following along, I’m doing the hamming_test.rb Exercism. It’s got a few tests. Here’s the first one:

# hamming_test.rb
  # ...
  def test_identical_strands
    assert_equal 0, Hamming.compute('A', 'A')
  # ...

my working solution (in regular, non-metaprogramming ruby), is:

# hamming.rb
# ...
  def self.compute(string1, string2)
    raise ArgumentError if (string1.length != string2.length)
    counter = 0
    string1.split('').each_with_index do |char, index|
      if char != string2[index]
        counter += 1
# ...

It’s a simple class method, takes two arguments, and even has an enumerable anti-pattern of using a counter outside the loop. This solution of mine is many months old, I’m not going to refactor that #each_with_index method. I know it’s itching for a #reduce, but let’s metaprogram it instead.

>> Read more