Ylan Segal

Talk: LA RubyConf 2015

Yesterday, I had the pleasure and privilege of presenting at LA RubyConf 2015. The conference was great. The presentation slides for my talk, Practical Unix for Ruby and Rails is now available.

It is powered by the awesome Remark.js, which has awesome features, like presenter mode that shows you notes next to each slide. Hit [P] to see my notes for the slides.

Update: Confreaks has posted the video of the talk

The REPL: Issue 14 - September 2015

How We Ended Up With Microservices

Phil Calçado writes a detailed post on the non-technical side of why Soundcloud moved away from a monolithic Rails app, in favor of a microservices architecture. Main reason: productivity. They were able to reduce their time-to-launch of new features from 66 days to 16 days.

A Gentle Introduction To Actor-based Concurrency

Originally published 2 years ago, Practicing Ruby provides a great explanation of what the Actor model looks like in Ruby. He solves the Dinning Philosophers Problem with bare ruby, the with Celluloid and then shows a simple implementation of actors in ruby would look like. Great read.

Implementing Worker Threads in Rails

Did you know that when a process is forked in ruby, only the main thread is copied and all other threads are dead? Neither did I, until I ran into it recently. Solving threading issues is very hard. This post has great techniques on how to use threads in Rails, even if using forking servers.

The REPL: Issue 13 - August 2015

Making Architecture Matter

In this keynote at OSCON 2015, Martin Fowler gives a great overview about how to think about software architecture to get the most benefit. As quoted in the comments:

It’s particularly relevant now as we push more and more toward continuous delivery, continuous deployment, features updated over the Internet all the time. That degree of being able to respond to change becomes important. That’s the economic reason why software architecture is important, because if we don’t keep good architecture, we are, in the end, deceiving our customers — in fact, stealing from our customers — because we’re slowing down their ability to compete.

Binary pattern matching in Elixir

Zohaib Rauf writes a great post that shows the great power of pattern matching in Elixir. Step by step, he builds a small module that parses PNG binaries. The explanations are clear and the resulting code is really elegant: One main function that parses the header and calls a private recursive function that parses each of the chunks. Worth a read, even if you are not into Elixir (yet!).

Work Hard, Live Well

Dustin Moskovitz writes about work life balance in the software industry and his personal experience at Facebook. The article resonates with me: I often say that in the modern world, sleep is a competitive advantage: Being tired decreases cognitive ability. When I was a freshman in college, I stayed up late to study for a physics exam, which I presented after only 4 hours of sleep. I had flunked because of basic algebraic mistakes applying the correct physical formulae. I took the lesson to heart. After that, for me exam preparation always included adequate rest.

Using ActiveRecord::Base#merge

The API for ActiveRecord::Base is very large, which makes it easy to miss some of the great convinences it affords.

1
2
3
4
5
class Account < ActiveRecord::Base
end

Account.new.methods.count # => 558
Object.new.methods.count # => 123

ActiveRecord::Relation#merge merges the conditions of two relations, allowing the use of scopes on both sides. This allows not repeating where clauses in separate places in the code base. Example, extracted from the Rails documentation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Instead of:

Post.joins(:comments).where(published: true, comments: { spam: false })

# => SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" WHERE "posts"."published" = ? AND "comments"."spam" = ?  [["published", "t"], ["spam", "f"]]

# Lets take advantage of scopes in Post and Comment:

class Comment < ActiveRecord::Base
  scope :non_spam, -> { where(spam: false) }
end

class Post < ActiveRecord::Base
  scope :published, -> { where(published: true) }
end

Post
  .joins(:comments)
  .published
  .merge(Comment.non_spam)

# => SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" WHERE "posts"."published" = ? AND "comments"."spam" = ?  [["published", "t"], ["spam", "f"]]

This way, each scope stays with the model it belongs in, removing any danger of duplicating domain logic (like what is consider spam) to a single place in the code. This technique is especially useful when taking advantage of more complicated (possibly parametized) scopes.

Book Review: Understanding Computation

I have two University degrees in different engineering disciplines, but came to Software Engineering without any formal training in Computer Science. I learned how to use databases and shortly later how to write programs. I mostly learned from practical books and online resources. All my deeper knowledge of computer theory came years later. Understanding Computation: From Simple Machines to Impossible Programs by Tom Stuart seems to have been written for people like me: Thirsty for knowledge about computer theory, with explanations written in the language we use every day and without the mathematical notation1.

In the book, Stuart uses Ruby to great effect to show examples of basic computer science. He builds two interpreters for a toy language, uses finite automate to implement a bare-bones regular expression language, explores Turing machines, illustrates how lambda calculus can be used to solve FizzBuzz and much more.

The explanations throughout the book are thorough and the code samples numerous. It is not a fast read: For some sections, I had to put down the book and think about what I read every couple of pages. However, I believe I have a better understanding of computer science after reading it.

I recommend the book to those Rubyists lacking a background in Computer Science or those that have one, but want to gain a perspective of computation without the formalism.

Links:


  1. I actually do like mathematics, but mostly as a tool to explore physics. My familiarity with the math underpinnings of computation is lacking.