Anthony Bailey Feed Public Domain Dedication

Where am I?

This tumblelog is a noisy stream of consciousness from Anthony Bailey. (And not Amazon.)

Tell me less:

For a lower traffic, more obsessively edited Anthony, see the real blog.

Ruby: Alternative action

Here’s an abstract description of a coding pattern in the Ruby language.

I often find myself uncomfortably coding an alternation like this one.

Now, moving details of the edge-case behavior into its own method is great, because it lets me concentrate on it in a context where it isn’t a distracting detail.

But creating this context has cost me; I don’t like the code for act, because most of it is about things other than the natural implementation, which is hiding off in another method.

Yesterday in Noel Rappin’s “Getting Started With Rails Testing”, I saw a concrete example of another formulation that I prefer.

(My #footnote is that in the unlikely scenario where the natural implementation of edge_case_step_2 can evaluate to false, you’ll need to stuff some extra truth in there somehow.)

I like this because it reads naturally, and is shorter due to the abbreviating power of the Perlish “and” for conditional actions.

[tag: software_development]

Comments (View)
blog comments powered by Disqus