Sunday, July 02, 2006

Cotta Power

So I got one feedback already for Cotta project, neat!

So the million-dollar question is: "How is Cotta different from other files system project like Apache commos VFS, other than support a lot less file system types?"

My first response is, "Ouch, that hurt!"

Second response would be, "Hmm... I think we should think through how we structure our website so that people would not try to compare it with the wrong kind of library"

From the beginning, the main reason behind Cotta project is to make file operations easy to write and test (or verify the behaviours, in jBehave term). So the main focus, which is also the power, of Cotta, is as below in two parts. We are still bouncing our thoughts around it, and the final documentation should be published on cotta project website.

Domain Driven

In my humble opinion, the current File class in Java, or the FileObject in Apache common VFS, or the Url in the VFS system of Borland JBuilder OpenAPI (BTW, it is nicely designed as well), all has one fundamental problem. For this or that reason, they still don't match fully to the domain, which is, in this case, NORMAL file system operation.

The number one problem I have is: "A file is NOT a directory". Namely, you want to list the children of a DIRECTORY, and the parent of a FILE should be a DIRECTORY. You should be able read/write only the content of a FILE, not a DIRECTORY. When your code has a path string, it should already know that it is a DIRECTORY or a FILE.

Also, when I delete a DIRECTORY, it should be GONE, instead of telling me that it is not empty. If I want a safety measure, my filesystem implementation should do that for me. My list can go on for a while if you let me...

Cotta was implemented in that way. As it was written, we have already got a project that does file operations, so we laid out the expected behaviours of the classes one by one, and implemented the code one by one. When it comes down to physical file system operations, there has been no guesses. The resulting API is compact, which is exactly what we intended.

Test Driven

Or Behaviour-Driven to be exact. When I write a class that operates on filesystem, I'd like to be able to verify the behaviour of that class. Even being a seasoned BDD developer, I still like to spend less time writing more functionality. And cutting the time spend on setting up and tearing down environment is always a good choice, hence the birth of XmlFixture (part of XPE, but you'll have to download the package to see the document), DbFixture, and now Cotta.

When it comes to behaviour verification, a common pattern is to go through "Dependency Injection". With Cotta, the domain class just need to work on a "FileSystem" instance being passed in, or one of the Cotta objects (TFileFactory, TFile, TDirectory) that can be created from the FileSystem. During the verification phase, the filesystem is replaced with a "InMemoryFileSystem".

Cotta also has FileSystem decorators that can be used to verify the behaviour on file system like read only (ControlledFileSystem), or file system with disk problems (CatastrophicFileSystem).

What Next?

The idea of making file system implementation for JAR file, FTP etc., was an after thought. I forgot to check with Apache common VFS again to see if I am re-inventing the wheels (as it turns out, I am, more or less). I think the next thing for us to do is to focus more on the two aspects that I have laid out above, and make it clear on the website about the real market value of this project.

Why dive into the Red Ocean when you have already discovered a Blue one, right?

9 comments:

Anonymous said...

What about ZIP files and other archives. They are both files *and* contain other files.

Shane said...

I said *NORMAL* file operations, not *ALL* file operations. If you want to focus on exception of every rule others trying to layout just to prove that they are not perfect, then you are missing the point.

Anonymous said...

I left that comment the other day.
Apologies for sounding harsh. I just happen to be very interested in this area at the moment and I just found Jakarta-Commons-VFS so I had it on the brain. I haven't even tried J-C-VFS yet so I guess I was really wondering whether Cotta was a response to problems you'd found there.

I agree about distinguishing files from directories... always found that strange in io.File.
I also very much like the idea of InMemoryFileSystem.

Thanks and good luck!

Anonymous said...

"When I write a class that operates on filesystem, I'd like to be able to verify the behaviour of that class."

So how is that different from Test Driven Development exactly?

Shane said...

Please do check out Dan North' blog, and especially the link to the presentation of Dan Astels'

Cotta is the first project that I have experimented with this idea and it has worked out well.

Anonymous said...

I've read both. Maybe you should read this:

http://www.diasparsoftware.com/weblog/archives/00000110.html

Shane said...

Isn't that the exact word Dave Astels said in his presentation? Or am I missing a point here...

Anonymous said...

The point is that Test Driven Development means EXACTLY what the BDD crowd are calling BDD. The fact that they have "invented" BDD only shows that they don't (or didn't) understand what TDD is, not that they've invented anything new. Using the BDD term just confuses things, is a lazy use of language and is a pointless new buzzword that has absolutely no meaning.

Shane said...

Points well taken, thanks for putting it here.

Yes BDD is TDD in the right way, as many have pointed out.

I don't believe that it is just a buzz word, or that it came out of people's lack of understanding of TDD, the same that I think about Domain Driven Design vs. Object Oriented Design.

Although having a debate with an anonymous through the comment to a blog about something rather irrelevent is a bit hard for me.