Includable ActiveRecord

I created a Ruby gem recently, called includable-activerecord. It’s pretty small, but I thought I might explain why I created it, and discuss its implementation. Classical Inheritance When you use ActiveRecord, you normally include it in your model like this: class User < ActiveRecord::Base # ... end Your User class is inheriting from the ActiveRecord::Base class. This is class-based inheritance, also called “classical” inheritance. (That’s “classical” as in “class”, not as a synonym for “traditional”.) Class-based inheritance represents an “is-a” relationship. So we’re saying that a user is an ActiveRecord base. Another way to say this is that User is a subclass of ActiveRecord::Base. There are a few problems with this. First, what is a “base”? The name was chosen because it’s a base class. But just like we don’t give factory classes names like UserFactory (at least not in Ruby), we shouldn’t name base classes Base. ...

February 10, 2014 · 4 min

Empathy

I facilitated our team retrospective this morning. I felt like we made a little forward progress, but not as much as I would have liked. But it really brought one thing to the forefront of my thoughts today — empathy gained through communication. We have a pretty large team by Agile standards — we had 20 people in our retro: 16 developers, 3 QA folks, and 1 manager. Out of those, only about 5 or 6 speak up regularly. I recently sent out a survey to the team, trying to get feedback on how we could improve our retros. A couple of the questions tried to get a feel for why people aren’t speaking up more. Only about half the people responded, and the answers didn’t really answer my question as well as I had hoped. ...

February 7, 2014 · 4 min

What I Want in a Blog Engine

I’m considering moving away from WordPress, for a couple reasons: Security. There have been several vulnerabilities over the past few years, and I’ve never really had a high level of confidence that it’s secure. In addition, I now find the whole PHP model — every web app running as a single user, instead of leveraging UNIX permissions — to be broken. Speed. I started to realize a couple years ago that a blog engine should generate static pages. The static pages should be updated whenever new content is added. There’s really no reason to re-generate the page every time someone wants to read it. At the very least, Server-Side Includes (SSI) or Edge-Side Includes (ESI) should be used. Now that I’m starting to actually blog consistently, it makes sense to change. But before I move to something different, I want to be sure that I find all the features that I need. This post is my thought process about what I want. ...

February 2, 2014 · 6 min

Testing Rails Validators

It’s challenging to test Rails custom validators. I recently had to write a validator to require that an entered date is before or after a specified date. It didn’t seem like writing the validator would be too difficult – I’ve written custom validators before, and date comparisons aren’t all that tricky. But when it came time to write the tests, I ran into several issues. And since I always try to follow TDD / test-first, I was blocked before I even began. ...

January 26, 2014 · 3 min

Introspective

Today I was informed that I’ve been impeding progress on our team. This was somewhat shocking, since I feel like I’m always pushing forward to make our team and myself better. Like most anyone, my initial reaction to criticism was defensiveness. I don’t handle criticism well. (You might find that hard to believe, after reading the rest of this post. Maybe it’s just the confrontation part I don’t handle well.) Thankfully the blow was softened somewhat, because the person providing the criticism didn’t tell me directly — they told Amos, a trusted colleague of mine. Amos then passed it on to me. I’m grateful for that — this is the best way for me to have received that criticism. ...

January 19, 2014 · 5 min

What’s Your Open Source Resolution?

I’ve been using GNU/Linux since 1994, starting with a Slackware 2.2 CD-ROM I ordered from the back of a magazine. I’ve been heavily involved in my local GNU/Linux community since 1999, and I give frequent presentations at various groups. I’ve made some small contributions to several Open Source projects. But I don’t feel like I’ve done enough to contribute to the wider community. So this year, I’m going to resolve to step up my contributions, and do more. ...

January 4, 2014 · 3 min

My Thoughts on Python vs. Ruby

I’ve been using Python at work for the past few months. I learned Python back in the early 2000s, but never used it for any large projects. I learned Ruby in late 2005, and it quickly became my language of choice for most cases. So while I still prefer Ruby, and will likely use Ruby more in the future than Python, I wanted to assess the strengths and weaknesses of Python in relation to Ruby. Perhaps some of the lessons could be applied when writing Ruby, and it could help to decide when to use each. Also, I’m interested in programming language design, and wanted to document pros and cons in that light. ...

February 22, 2013 · 5 min

Debugging Pattern – Grenade

I’ve been more interested in programming patterns lately, partly due to the Ruby community’s recent interest — especially the Ruby Rogue podcast’s love affair with “Smalltalk Best Practice Patterns”. I consider most of the patterns in “Smalltalk Best Practice Patterns” to be patterns “in the small” — things that are typically employed on a single line or method. The Gang Of Four patterns are more medium sized, dealing with methods and classes. The PEAA book covers architectural-scale patterns. I suppose “The Pragmatic Programmer” and similar books could (should!) be considered to be very general patterns, mostly about the practice of programming. ...

January 11, 2012 · 2 min

Write Comments For Yourself

Amos and I got in a heated discussion recently on whether we should write a single line comment to better explain some code. (The code in question was Amos’s very elegant solution to testing whether a job got sent to Resque.) Amos doesn’t believe in writing comments much at all. He thinks that if you’re writing a comment, it means that you’re doing something wrong, and that you probably need to write the code more clearly. ...

January 10, 2012 · 2 min

Bulk Rename in Bash

Here’s a relatively simple way to rename a bunch of files from the command line. It uses sed within a command substitution to compute the new names from the old names. In this example, we’re renaming files that start with “ABC” to start with “XYZ” instead: for i in ABC*; do mv $i $(echo $i | sed -e s/^ABC/XYZ/); done You’ll have to use shell globbing (wildcards) in the first part, to determine which files will be the source of the renaming, and regular expressions in the second part to translate the old names into the new names. ...

August 26, 2011 · 1 min