Archive for the ‘Software Development’ Category
RESTing at Øredev
There was quite a bit of REST chatter at Øredev last week. I sat in on the REST in Practice tutorial by Ian Robinson and Jim Webber (if you have not read the book they co-authored, then do – it’s really well written). There were a couple of things that these two guys cleared up for me, in the tutorial and in conversation during the week.
Application state is in the head of the consumer, not the provider of the resources. This suggests that we should be able to recompute the state of application at any time. If we can recompute the application state, then we don’t need to explicitly implement the entire application state machine in the provider, nor the client.
You may start off with modeling an application state machine on paper and discover the life cycle of resources. Implementing this is then simpler because we are only need to implement the lifecycle of the resource, not the entire application state. The way the consumer drives the state machine is just be reacting to available transitions in the representation of a resource. Now you give the provider the freedom to change the application state machine and the consumer will react to the new state machine by discovery. That is significant.
Use hypermedia to refer to yourself. This came up in the tutorial because I objected to a resource including a hypermedia link to itself, regardless of its state. To me, it seemed to have little value because you already have the representation of a resource in a particular state, so why include hypermedia for itself. For example, this is what a resource will look like without a link to self.
<Order>
<id>823763</id>
...
<links>
<link rel="pay" href="http://example.com/payment/823763"/>
</links>
</Order>
Now, if I want to GET the original order resource, I would need to know that there is some URI that includes the id of the order. And, so, we end up publishing a URI template such as
GET http://example.com/order/{id}
If we include a link to self, then the representation looks like this.
<Order>
<id>823763</id>
...
<links>
<link rel="self" href="http://example.com/order/823763"/>
<link rel="pay" href="http://example.com/payment/823763"/>
</links>
</Order>
Look Ma! I don’t have to expose a URI template anymore. It’s all discoverable. That is significant.
REST support in WCF is heading in the right direction. I also listened to Glenn Block’s talk on his team’s work on HTTP and REST support in WCF. It’s still early days but I think they are paying attention to experts in this space and giving priority to the developers that will use it.
In the past you would have to map a very specific, template based HTTP GET operation to a method like this (excluding the additional endpoint configuration too!)
[WebGet(UriTemplate = "{id}")]
public Contact Get(string id, HttpResponseMessage resp) { ... }
What Glenn showed was a method signature that resembled the HTTP operation on the resource.
public Contact Get(string id, HttpResponseMessage resp) { ... }
Sure, it’s using a lot of convention over configuration to get rid of the attributes. Now that may not seem like a big deal, but I do think that it is moving the HTTP abstraction down to a level that is more resource friendly. When you are building a RESTful architecture, then you do think quite naturally in terms of the resources and their allowable HTTP operations for obtaining state or triggering a state transition. By moving away from mapping HTTP operations to a service contract, it introduces the necessary mental shift from RPC to Resources. And that is significant.
Practical Scrum with Kent Beck
SD Times has started a series of Leaders of Agile webinars. The last was on Continuous Delivery with Kent Beck facilitating a discussion with Jez Humble and Timothy Fitz. The next in the series is on Practical Scrum which will, again, be lead by Kent . I think it will be a interesting perspective coming from the person that brought us Extreme Programming and so much more.
Sign up, it’s free.
This mess started long, long time ago
My son borrowed Asterix and Cleopatra from Claremont Library last week. It’s been ages since I read anything from that series. But page 2 really had me chuckling. There is an image of the page online, but it’s bit hard to read. So, here’s the dialog.
The scene: Cleopatra has been challenged by Julius Caesar to build a grand palace that will prove that the Egyptians are an advanced nation. She summons Edifis, her architect.
Cleopatra: Edifis, I have summoned you because you are the best architect in Alexandria – which is isn’t saying much.
Edifis: Oh!
Cleopatra: Don’t answer back! Your buildings are flimsy. You can hear every word the neighbours say. The ceilings fall in!
Edifis: It’s these modern materials… Actually, what I really want to do is build pyramids and …
Cleopatra: Silence! You have just three months to make good. You are to build Julius Caesar a magnificent palace here in Alexandria.
Edifis: Did you say THREE MONTHS?
Cleopatra: If you succeed, you will be covered in gold! If not, you will be thrown to the crocodiles! You may go.
(Edifis walks out)
Edifis: (thinking) Three months! I’d need supernatural powers to do that! I’d need someone who can work magic.
Edifis: (shouting) Got it! I know the very man! He can work magic!
Now, where have we seen that before?
(And just get the original book and read on about mule-driving the slaves to haul huge blocks of stone … classic!)
Patterns at the September SPIN Event
I suspect that many people did not understand what I meant about forces at play and that patterns describe a solution to bring some harmony among the forces in the problem in a particular context. For the example of the airplane and wanting to serve the right meal to the right person, the challenge is to serve the meal without knowing about the seating arrangement on the plane, and still sequentially access each seat. Let’s look at how to get rid of the need to know the seating arrangement.
We start with the solution where we need to know the arrangement of seating and number of seats too. BTW, it’s ruby code.
for row in (0..29) do # 30 rows
for pos in (0..5) do # seat A-F
passenger = airplane.seats[row][pos]
next if passenger.nil?
passenger.serve_meal("nut free") if passenger.meal() == "nut free"
end
end
Of course, if we know the seat number, for example, 15C, then we can do this. But that does not help at all.
airplane.seats[14][2].serve_meal("nut free") if airplane.seats[14][2].meal() == "nut free"
But, we still expose the data structure of the seats. So, let’s make it a little better by using the iterator pattern on the data structure for the seats.
airplane.seats.each do |row|
row.each do | passenger |
next if passenger.nil?
passenger.serve_meal("nut free") if passenger.meal() == "nut free"
end
end
We could be cuter and do something like this and hide the seats array, but we still expose the numbering scheme of the seating.
airplane.serve_meal("15C", "nut free")
So, we can have the iterator on the seats data structure, which helps a bit. But we can make it a lot better if we put an iterator on the airplane itself. Now, we just care about occupied seats.
airplane.each_occupied_seat do |passenger|
passenger.serve_meal("nut free") if passenger.meal()
== "nut free"
end
In the airplane class, we have the following.
class airplane
...
def each_occupied_seat &block
@seats.each {|row| row.each { |pos| yield pos if not pos.nil?} }
end
end
We are using iterators on the encapsulated seats structure and exposing a new iterator for the airplane. Also, we are only work with seat that has a passenger
So, we started out with a deep need to know the structure, layout and limits of the seating in the airplane. Then we started hiding the data structure for the seats, put iterators on this seats data structure which helped a bit. But the real breakthrough happened when we started asking the airplane to just give us a way of sequentially accessing each seat that had a passenger. No more conflicting forces, just a simple harmonious way to access each occupied seat on the plane. And when the plane seating changes, we don’t care.
What freedom?
At the Scrum gathering I had a tiny little conversation with Lorraine Steyn of Khanyisa Real Systems and Henrik Kniberg of Crisp about some of the values in our organisations. At the top of Henrik’s value list was Freedom. It seemed straight forward enough, until I started thinking about what freedom means to me.
My early perspective and experience on (the lack of) freedom is based purely on oppression of apartheid. Ok, that’s over, so I am now free. Right?
Then John Lennon’s Imagine lyrics sang through my head. If we’ve nothing to kill or die for, will we have universal freedom?
Hold on, what about when Janis Joplin sang Me and Bobby McGee – “Freedom’s just another word for nothing left to lose”? That sounds too dreary for a concept that should make me happy.
Tonight I saw a quote by Maria Montessori on the wall next to my wife’s desk at home. It’s been there forever and it says:
“The essence of independence is to be able to do something for one’s self.”
I like this the most. Be able to something for yourself and you will gain independence which sets you free. It also reminds me of the self-organising mantra in Scrum-land. Self organising implies that the team wants to be able to manage themselves so that they achieve independence (freedom). But, there is a little spark of conflict in here. As individuals we also have priorities and values, which is not necessarily aligned with that of the team. Is it acceptable to compromise just to subscribe to the homogeneity of the team?
I think it’s a long walk to freedom.


