The promis of Shalt.

Posted by Uncle Bob on 12/07/2008

When writing requirements we often use the word “shall”. In Rspec, we use the word “should”. Some folks use the word “must”. These statements create the connotation of a law, or a command.

Let’s take a very old law: “Thou shalt not kill.” There are two ways to look at this law. We could look at it as a command[ment], or … we could look at it as a promise.

Here are the two different versions:

The difference is in the punctuation. And what a difference it makes. One is a stern order, a demand. The other is a promise… a confident guarantee… a statement of simple truth.

Now look at these rspec statements from RubySlim. I started writing the specs this way because it was shorter; but I like the connotation of confidence and truth. “I can has cheezburger.”

describe StatementExecutor do

 before do

   @caller = StatementExecutor.new

 end

 it "can create an instance" do

   response = @caller.create("x", "TestModule::TestSlim",[])

   response.should == "OK"

   x = @caller.instance("x")

   x.class.name.should == "TestModule::TestSlim"

 end

 it "can create an instance with arguments" do

   response = @caller.create("x", "TestModule::TestSlimWithArguments", ["3"])

   response.should == "OK"

   x = @caller.instance("x")

   x.arg.should == "3"

 end

 it "can't create an instance with the wrong number of arguments" do

   result = @caller.create("x", "TestModule::TestSlim", ["noSuchArgument"])

   result.should include(Statement::EXCEPTION_TAG + "message:<<COULD_NOT_INVOKE_CONSTRUCTOR TestModule::TestSlim[1]>>")

 end

 it "can't create an instance if there is no class" do

   result = @caller.create("x", "TestModule::NoSuchClass", [])

   result.should include(Statement::EXCEPTION_TAG + "message:<<COULD_NOT_INVOKE_CONSTRUCTOR TestModule::NoSuchClass failed to find in []>>")

 end

end

This makes we want to change all the “should’ statement into “will” statement, or “does” statements.

Posted by Uncle Bob on 11/30/2008

I want the JetBrains and Eclipse people to automate The Saff Squeeze

omments

Leave a response