Tuesday, January 15, 2008

Behavior Driven Development

I was looking at RSpec(http://rspec.info/) as I want to use it in a open source project. The definition of RSpec says that its a Behavior Driven Development framework for Ruby. As a TDD practitioner, I have been writing tests using xUnit frameworks. This will be my first experience with BDD frameworks. But how BDD differs from TDD ?

In test driven development we write tests before we code. However, testing the code and application is not the sole purpose of writing tests.TDD is not only about writing tests. Its about writing specifications for individual piece of code in form of tests, which should (ideally) lead to better design. So TDD is about specifying requirements and design and not only testing. BDD makes this fact explicit. It uses proper vocabulary and has emphasis on using the proper words (e.g. specification instead of tests). BDD gives more emphasis on coming up with the behaviour and specification rather than tests.

BDD is not a radically new way of thinking (like TDD is). Its just a improvement, a next step in TDD thinking. It combines the aspects of Domain Driven Design with TDD. It defers from TDD in a sense that we specify behaviour of the application rather than testing its implementation.However, just like TDD, we should do it in small steps, writing down the specification for small part of app before the part is implemented.

BDD uses Ubiquitous language - language which is equally understood by developers and users. Rspec, which a Behavior Driven Development framework for Ruby, allows us to define specifications in language such as "should add two numbers" or "should have score greater than 50". This kind of specification is more intuitive than unit tests.

So in short, BDD frameworks allows us to write executable specification and acceptance criteria. However, I still have some questions like - Can we do BDD with xUnit frameworks which are defined for TDD ? Do we still need unit tests to test the application at granular level or we should use BDD framework for that purpose? Hopefully, answers to these questions will be clear once I become more familiar to BDD style.

On the way of Learning RESTful way

REST, which stands for Representational State Transfer is an architectural style of developing the web services. I first came across this term when I attended the Sriram Narayan's (a fellow thoughtworker) presentation. I was quite impressed with the concept and was planning to read about it in detail since long. When I started reading, I came across XML-RPC and SOAP which are other protocols used to communicate between two web services across network. As usual, I was not aware of them and searched to see exactly what they are. In short, this is what I found.

# XML-RPC : As it's name suggests, its a remote procedure call protocol which allows applications running on different machines (or different platforms) to communicate through remote procedure calls. It uses xml as message format and uses http as transport mechanism. The format of messages in XML_RPC is very simple and contains minimal data types. In fact, simplicity is the goal of XML-RPC.

# SOAP : SOAP stands for Simple Object access protocol which is a protocol for communicating across computer network using xml messages. It is successor of XML-RPC protocol.Its mostly used for communication between web services.
The advantage of SOAP is that it uses xml for communication which can communicate with different platforms and different applications.
However, as its uses xml, it can be slower as serialization, deserialization is required, which is a expensive operation. Also, the xml structure of message can be very complex and verbose. The other problem is that it uses http, which is a application protocol, as transport protocol.

Equipped with this basic knowledge, now I am in better position to read about REST..

Thursday, January 10, 2008

Playing with svn delete and svn status

I was playing around with svn recently while working on story related to svn delete. We are doing a physical delete of a folder in code and then svn delete from powershell script. But somehow svn delete doesn't work and the deleted folder comes back again on svn update.

I found out that if we delete the folder (or file) physically from the file system and then do a svn delete for that folder, it doesn't get deleted from the svn and comes back on svn update and this was the cause of my problem. However, if we do svn delete directly, the folder gets deleted properly and doesnt come back on next update. Obviously, the folder comes back on svn revert as we haven't committed yet.

I tried to figure out if I can do something else rather changing the code to do svn delete. I tried to do svn commit in the script after doing svn delete. However, commit also commits other changes apart from deletions. When I tried to do commit by specifing folder name like -

svn commit $matches["file"] -m $comment

then it gives error -

svn: Commit failed (details follow):
svn: Entry for 'C:/foo' has no URL

This is not unexpected. This happens because the folder is not present in the given path
as it is already deleted. So, I was not able to do commit just for the deletion.

Finally, we changed the code to do the svn delete at first place rather than doing physical delete. :-)


I noticed that svn status also behaves little strangly. svn stat (svn status) is supposed to give 'D' for the deleted files/folders and '!' for the files that are missing i.e. deleted without svn in the first column of status message. This works fine in most cases.

Consider this scenario- if you physically delete a folder with svn, status gives '!'. If you restore the folder and do svn delete on the same folder, it gives D in the status, which is exactly as expected.
Now, if you revert the folder and do the physical delete, you will expect that svn stat will give '!' as usual, but this time, svn status gives 'D' !

It seems that the svn remembers that delete was invoked on the folder and gives D even if it's a file system delete. And now onwards, the svn will keep on giving 'D' in the status for that folder even if you do physical delete or svn delete. This behaviour caused some confusion. Is it a svn bug ?