Friday, January 13, 2006

Fragile Development

There might be a problem when...

instead of refactoring duplicate code you just ignore it.
#region simianignore - logic same among all screens

you hear:
"I don't like to check in often, the tests take too long to run"

Friday, January 06, 2006

I prefer Rake to NAnt (#2)

I prefer Ruby's libraries to NAnt's tasks.
Recently, I was asked to add a step to the build file that would delete all build outputs that were older than 2 weeks old. The build output is stored in a folder in the distrobution folder. I'm not even going to attempt this task in NAnt, but using Ruby's find, delete, and fileutils the code was quite easy to write. (I admit, this could probably be done even better, but this was the first thing that came to mind.)
require 'find'
require 'date'
require 'fileutils'

root_dir = "C:/Dist"
two_weeks_ago = Date.today - 14

puts "deleting files last modified before #{two_weeks_ago}"
Find.find(root_dir) do |path|
if File.dirname(path) == root_dir
file_modify_date = Date.parse(File.mtime(path).strftime("%m/%d/%Y"))
puts "#{path} last modified on #{file_modify_date}"
if file_modify_date < two_weeks_ago
puts "#{path} removed"
FileUtils.rm_rf(path)
end
end
end

I prefer Rake to NAnt (#1)

While working with Rake and NAnt I've found several reasons I prefer Rake. And, I've received several requests for a pro/con list concerning Rake. So, I'm going to start keeping a list. Here's reason #1.
I prefer escape characters (\") and Q delimiters (%Q) to entity codes (&quot;).
For example, executing an external program where the 1st parameter needs to be in quotes but not the second.
Rake (option 1): exec "foo.exe \"some text\" bar"
Rake (option 2)*: exec %Q[foo.exe "some text" bar]
NAnt: <exec program="foo.exe" commandline="&quot;some text&quot; bar"/>
*option 2 provided by Martin

NAnt exec: add quotes to commandline

After posting NAnt exec: arg || commandline, an anonymous reader asked how to add quotes to some arguments and not others.

A simple solution would be to use commandline and delimit the string with single quotes.
<exec program="ruby" commandline='parse_text.rb "some text file.txt"'/>
However, this solution feels like a hack and isn't immediately obvious.

Another (even less obvious) solution is to use &quot;.
<exec program="ruby" commandline="parse_text.rb &quot;some text file.txt&quot;"/>
This doesn't read very well, but it feels less like a hack because you can use a standard double quote delimiter.

Either option you choose isn't very pleasing. Which leads me to reason #1 why I prefer Rake to NAnt.

Trust Visibility

Long before I joined ThoughtWorks I wrote a Data Access framework with a very simple public interface. The entry point to the framework was a IDataManager interface that contained Save(..), Delete(..), and Find(..). The framework was composed of several collaborating classes, but only the IDataManager interface was public. I designed the code this way because of fear. I was afraid that if I gave developers the rope, they would hang themselves.

During the development of this framework I came up with the idea of Accessing Private Members using conditional compilation. While interviewing with ThoughtWorks I briefly discussed this situation with Greg Warren. He suggested (but did not take credit for the idea) using a correctly scoped interface and making the methods of the concrete classes public. At the time, this sounded like a large risk. I didn't trust the other team members enough to give them that option.

Since joining ThoughtWorks, my opinion has completely changed. I now subscribe to the idea that a language should only have public and protected access (which I first heard from Zak Tamsen). So many language constructs are designed to protect us from ourselves that we often tie our own hands together. I'd prefer to have the rope and see what I can do with it. However, I strongly believe that I changed my mind based on the fact that I now trust the team I am working with. Because of this trust I don't feel I need to tie their hands together. And, with untied hands, my teammates produce some pretty brilliant ideas.

To me, this proves once again that People Matter Most.