jeff lunt



I write code primarily in ruby. here are a few things that are different from the norm in my personal coding style.

I don’t use the private nor protected keywords in languages

when writing OOP code I avoid using private, protected, or any other keyword in a language intended to hide information or implementaion details. instead I prefer to adopt a naming scheme to indicate to other users of the code what parts are intended for public consumption, and what is intended only as supporting methods for implementation. for example, when writing a ruby module with some public and some supporting methods, I’ll do something like this:

module SomeModule
  class << self
    def public_method1          # meant for public consumption
    end

    def _support_method1        # supporting method, note the underscore
    end

    def public_method2          # meant for public consumption
    end

    def _support_method2        # supporting method, note the underscore
    end
  end
end

the reason I do this is a few reaons

frame problems as data pipeline problems when you can

while I don’t write code in lisp, some of my most used capabilities within ruby are the methods in the Enumerable module. I find these so useful that I will often compose a solution to a programming problem as a series of steps operating over some kind of collection or list, as one often does in lisp. you can also see programming problems solved as data pipelines in a linux shell’s use of the pipe (|) operator. the concept is roughly the same.

use simple, open data structures rather than custom data structures

a few guidelins:

testing libraries

if I want to use a testing library, I’m generally going to choose a simple assertion-based library. I’m not a huge fan of testing libraries that use English-like phrases to represent program output. I feel that computers are too precise, detailed, and intolerant to vauge language to work well with English-like phases.

to put this another way:

  1. if I have to choose between explicit vs. vague I’ll generally choose explicit, even if that means being more verbose.
  2. if I have to choose between being extra layers of abstraction in a system to make it seem more English-list, or fewer layers that are perhaps more compact in their expression, I will choose fewer layers. adding more layers of abstration and indirection might seem like it helps code organization because every little method has its place, but it can also magnify the number of layers and files someone must understand to make sense of the code.

an example

I wrote a small ruby gem, called tiny_bus that follows the style points above. there aren’t any tests, but it’s well documented and works, and it includes examples on how to invoke and utilize the class. a quick, working example with supporting explanations is what most developers need more than for the code to be neatly tucked away in many little boxes.