Create localhost Aliases for Different Projects
Code: , , , ,
Comments Off on Create localhost Aliases for Different Projects

As a consultant I’m getting set up to develop on a new Rails project every few weeks or months. And I’ll jump back to an earlier project to answer questions, fix bugs, fix typos, etc. Eventually, something overlaps between them. I got bit by this again, so I wanted to write it up.

Continue this post

Case Sensitivity in In-Page Anchors
Code: , , ,
Comments Off on Case Sensitivity in In-Page Anchors

As I’ve been working on Chibrary, I ran into a small cross-browser compatability issue: only some browsers treat anchors as case-sensitive. The call numbers that uniquely identify messages would be perfect for linking to in the middle of a long discussion, but some of them only differ by case.

So I wondered: is that acceptable in linking to an anchor inside the page? A quick experiment with Firefox worked fine, but I wanted to be thorough.

Continue this post

Dual-Booting Arch Linux on Lenovo X1 Carbon 3rd gen
Code: , , , , , , , ,
Comments Off on Dual-Booting Arch Linux on Lenovo X1 Carbon 3rd gen

I decided to replace my mid-2011 Macbook Air 3,2 with a non-Apple machine, but every laptop I looked at was unsuitable. Most were overpriced, with a big and clunky design. The Lenovo X1 Carbon was promising, but the 2nd generation had a keyboard that was just too weird (and the function keys changing modes means you can’t touch-type them anymore). Standard qwerty is bad, but it’s the devil I know.

Continue this post

Isolating Polymorphism
Code: , ,
Comments Off on Isolating Polymorphism

I’m reading Code Complete, 2nd ed and it’s been like catching up with an old friend. I remember reading the first edition at my first tech job fifteen years ago. At the time a lot of it went by me, but rereading I can see a lot of things I had to learn on my own.

Continue this post

Type-Checking Interface in Ruby
Code: , , , ,
Comments Off on Type-Checking Interface in Ruby

One of my favorite parts in Sandi Metz’s excellent Practical Object Oriented Design in Ruby is when she describes how to enforce lightweight interfaces so that multiple objects can play a role reliably. And I thought: how I can I enforce this in a much-more heavy-handed and annoying way?

This question also ties into two ridiculous
tweets of mine:

Continue this post

Prefer: Censorship
Code: , ,
Comments Off on Prefer: Censorship

In the Mozilla blog post Prefer: safe, I read:

Mozilla believes users have the right to shape the Internet and their own experiences on it. However, there are instances when people seek to shape not only their own experiences, but also those of young users and family members whose needs related to trust and safety may differ.

We’re pleased to announce a smart feature in Firefox for just this type of user called Prefer:Safe, designed to simplify and strengthen the online trust and safety model.

I thought this was encouraging. The “Prefer: safe” was clearly a browser header, and this description sounded like it would indicate to the site the browser wanted increased privacy and security controls, or at least better defaults. I thought it unlikely that a lot of sites would honor it, but maybe it would improve things.

Continue this post

Integration as Composition
Code: , , , , ,
Comments Off on Integration as Composition

I’m puzzling over the design for a worker and would appreciate your comments on it. I started with the pain of an ugly test, made an interesting refactoring, and decided to drop the test entirely, but I’m not at all sure this is the right decision.

In my mailing list archive Chibrary, I want to sum up the number of threads and messages in a month to present on archive pages. The MonthCountWorker takes a Sym, a unique identifier for a list’s slug + year + month, fetchs the threads for that month, sums them, and stores the sum. The code is trivial, right?:

Continue this post

Builder Methods
Code: , , , ,
Comments Off on Builder Methods

I was reading Corey Haines’ book Understanding the Four Rules of Simple Design (capsule review on the 2014 book reviews post) when I read:

In fact, over time I’ve developed a guideline for myself that external callers can’t actually use the base constructor for an object. Put another way: the outside world can’t use new to instantiate an object with an expectation of a specific state. Instead, there must be an explicitly named builder method on the class to create an object in a specific, valid state.

This was a brief aside at the tail of a longer discussion of interdependent and redundant tests. It really caught my attention and I’d like to hear it more thoroughly investigated. In the hopes of attracting Corey’s attention, I offer this cat pic and an exploration of the benefits of a similar practice I have:

Continue this post

Two Designs for SequenceIdGenerator
Code: , , , ,
Comments Off on Two Designs for SequenceIdGenerator

In my previous, marathon post on id generation, I mentioned that I was generating unique sequence numbers. It was straightforward to write a class to generate them:

Continue this post

Distributed ID Generation and Bit Packing
Code: , , , , ,
Comments Off on Distributed ID Generation and Bit Packing

There are two ways for programs to collaborate: they can communicate their shared state or they can partition the work so they don’t need to know each other’s state. As I’ve been rehabbing the code for my mailing list archive Chibrary I ran into this issue, and the design constraints made for an interesting puzzle. I need to generate unique IDs in multiple programs at once, and they need to be short enough to fit in URLs.

Writing is nature’s way of letting you know how sloppy your thinking is.

At more than 3,000 words, this is an unusually long blog post for me. This problem has a lot of considerations to balance (and you’ll see a lot of parenthetical caveats). I like to work through problems by writing out my thoughts, constantly tinkering with possibilities and revisiting ideas in light of new constraints or insight. I thought my (heavily) revised notes might make for an interesting post as I attack the problem from several different approaches and end with a solution that nicely connects theoretical and practical considerations. As a bonus, maybe someone will tell me I’m approaching this all wrong or ignorant of a known best practice for this sort of thing before I go live. With that preamble rambled, let’s dig into the problem.

Continue this post