Skip to content

Instantly share code, notes, and snippets.

@geeksam
Created February 20, 2015 19:03
Embed
What would you like to do?
OFFS Indentation example (OFFS: https://github.com/jwilger/offs)

I propose the following convention: the actual lines of code that are directly related to the OFFS gem itself should be aligned with the left margin. Code inside the would_like_to and may_still_need_to blocks should be indented "normally", as though the surrounding OFFS do/end lines were not present. See the example Ruby file also in this gist.

This convention serves two purposes:

  1. It provides a visual indication that something in the file is "weird", thus calling our attention to the complexity penalty being imposed by carrying extra branches in VCS.
  2. When the feature itself is eventually cleaned up, the diff will be a straight deletion, not the deletion-plus-insertion one would otherwise get from deindenting a block of code. This will make it more obvious if someone deletes one branch and makes an edit in the other in the same Git commit.
class Foo
def do_something
OFFS.so_you_want_to(:use_my_million_dollar_idea) do |you|
you.would_like_to do
# this is where you put the new code that will run when the flag
# is *on*.
end
you.may_still_need_to do
# this is where you put the old code that will run when the flag
# is *off*
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment