Services and Pub Sub

The Publish-Subscribe pattern is a great way to make code modular and decoupled from the rest of the architecture. It also has a nice side-effect of making testing easier and classes smaller. In a pub-sub pattern, publishers don’t know anything about its subscribers and subscribers don’t know anything about who is publishing to it. Subscribers are simply listening for specific messages and handling them accordingly and publishers are simply broadcasting messages....

July 3, 2013

Task Based Threading

Task based thread execution is a great way to do threading in an application. Taking the same idea that is used in web development can be applied directly to any application that can utilize threads. When working with a web application, often the application will need to send an email to a customer without slowing down the user’s request. Background jobs are typically used for slow; long running tasks that can be processed later....

June 29, 2013

Null Objects

Rails is a wonderful library. It’s a framework that is opinionated and requires some footwork on the developers part. One such issue is returning nil when the return type is an object. Returning nill doesn’t provide the view enough information about what actions to take and leads to complex whack-a-mole scenarios. The solution to this problem is to introduce a NullObject into the application. There are null object libraries already available, but they are so dead simple to write that it’s not necessary to use one....

June 24, 2013

Query Objects

I’m trying to migrate my models to be dumb data bags that have some useful state altering methods. I’ve found that using query objects, I was able to reduce the complexity of some of my models and controllers. The Problem My User model is gigantic. It’s well over 600 LOC, and it’s growing at a scary rate. Testing is becoming a nightmare because of all the methods. A few methods I have realized, I could remove completely and extract them into query objects....

April 19, 2013

Ruby Mixin Exploration

Recently I’ve been playing with Ruby’s class_eval and define_method to append methods to an object. Meta programming is something new for me and I had a problem that would benefit from using some of Ruby’s cool features. The Problem There was a model that had 6 fields that needed to be generated at some point in time. Some fields had to be unique and others had to be generated a bit differently....

March 20, 2013

No Internet Means Better Test Isolation

One day I found myself riding in a car with my family and it was a long road trip, with little to no internet and realized that my tests required internet connectivity. I was also heavily dependent upon code examples that I could find. I’ve been absolutely horrible with testing my code. I would write code, test it out in the ruby console and then push it live. It felt like I was moving fast....

February 1, 2013

Organizing Delayed Jobs

I despise consuming 3rd party APIs for one reason, speed. Many of the APIs I have to consume on a daily basis, respond slower than it would take to deliver an email. But, their integration with our application is absolutely critical. They are so critical infact, that if an error should happen during any point of the commissioning, then I need to be notified and or the job needs to be reattempted at a later date....

December 13, 2012

Flying with php

I discovered the Flight micro-php framework this week. I found it because I was looking for a simple PHP 5.3+ framework that didn’t have a large amount of extra cruft. I had a project to do for my Database class at UTSA where we had to utilize an Oracle database. Not exactly my choice for databases, but we had to make do with what we were given. It is a very sparse framework that looks very similar to Sinatra except it is even lighter....

November 30, 2012

High Level Low Level Compilation

I have been staring at Ruby for so long that I have become disgusted with low level languages like C or C++. Mid level languages like Java still make me cringe when I look at them. As I sit and write code in Ruby that runs on a terribly slow VM I begin to think. Why don’t high level languages like Ruby or Python compile into assembly level code like C does when it is compiled?...

August 8, 2012

Exceptional Rails Handling

When I am writing a Rails application it starts out simple with a few if @something.save lines that are pretty self explanatory. Then the application grows and starts to become hairy. Take my contrived example with a grain of salt as I can’t show you production code that I am using. # app/controllers/widgets_controller.rb class WidgetsController < ApplicationController # # Other methods go here # def something # Maybe we handle the update in a special way widget = Widget....

March 25, 2012