Thursday, August 21, 2008

Red Gate purchases Reflector

Red Gate software has purchased, and take over future development of, Lutz Roeder's uber-popular tool.

Under an agreement announced on Wednesday 20th August , Red Gate will be responsible for the future development of .NET Reflector, the popular tool authored by Lutz Roeder. Red Gate will continue to offer the tool for free to the community.

Is this good news? I'm not sure. Red Gate says they will continue to offer Reflector as a free community-based tool, so it remains to be seen what this really means for .Net coders everywhere.

Click the link for full article.

Technorati Tags: ,,

Friday, August 15, 2008

Keep It Simple...

Programming is like sex. One mistake and you have to support it for the rest of your life.
~Michael Sinz

I was in the process of reviewing some documentation for a bit of popular legal software my employer purchased a while back, when I stumbled upon an interesting tidbit. I recognized it immediately for what it was, but I'll get into that a bit later. 

This particular vendor provides a RESTful API into their offerings. When invoking several of said API's methods, you can specify, as a parameter, a contactId in either one of two formats, termed Windows and Web.

The Windows format looks like this: 2/2195. Essentially two numbers delimited by a slash. Easy enough!

The Web format, on the other hand, looks like this: 8589936787.

So, to call their RESTful findContacts method, I would pass one of these two formats, thusly:

http://…/findContacts?contactId=[insert contact id here]

Reading further, I discovered that the Web format is actually a fancy calculation computed against the parts of the Windows format, thusly:

  • Source ID = 2
  • ID = 2195
  • Web ID = (2 * 2^32) + 2195

The result of that calculation would give us the longer Web format: 8589936787.

According to the documentation, this was recently added as a "feature", which I suppose could be marketed as "slashless Web Ids". But, as far as mine eyes can see, really adds no value to the application. 

What it does offer is oodles of cyclomatic complexity, the extent of which may not be apparent at first glance. Let's take a closer look:
  1. Following this change, all developers on the project need to be educated that IDs can be input in two different ways. Why do they need to be aware? So that they don't assume that all IDs going forward will contain a slash, and can revise the way they handle ID input. Maybe they need to call a different function to parse IDs. Maybe they don't need to do anything at all. But I'm betting that somebody, somewhere, will either need to send an email about this change, spend an hour discussing it in a meeting, or add it to the project's internal documentation.
  2. The test cases developed before this change are no longer valid for testing ID input. Now you have to test the case where ID input doesn't contain a slash (the Windows format), as well as the detection of the ID input format (i.e. running different code based on whether the ID contains a slash or not).
  3. In this case, a new web method was developed, convertDualId, which does the math for any math-challenged developers out there. Something else that needs to be tested.
  4. The documentation I'm reading contains three (3) HTML (.chm file) pages of documentation on this topic, explaining the difference between the two formats, and how to do the math to calculate the Web Id if you don't want to call the new convertDualId method. All of which needs to be validated, proofread, and so on.

And all that for... what? Seriously. To calculate the Web Id, I still need to have the two original slash-delimited values, so what am I gaining? I'll tell you what I'm gaining: an id that doesn't contain a slash.

Woop-te-doo.

If a slash is bothering you that bad, I can think of several other much simpler alternatives. Like, say, just HTML-encoding the thing as %2F. But of course that wouldn't properly showcase the developer's creativity, virility, and prowess.

And therefore I must conclude that what this is, in fact, is gold plating at its finest. An anonymous developer's proud signature, showcasing his unique ability to do maths.

Hardly aware is he that writing code like this is akin to locking a ball and chain around his ankle, forcing him into supporting this unnecessary code until the end of time. Or at least until he realizes what he's done and leaves for unspoiled pastures.

Keep It Simple, Stupid.

Sunday, August 10, 2008

xmlns='' was not expected

If you ever run into this XmlSerializer error: it's thrown because the name of the class being deserialized and the root node are not the same.

For example, if you're deserializing XML that looks something like this...
<PersonData>
<FirstName>Bob</FirstName>
<LastName>Black</LastName>
</PersonData>


...into a class called...


public class PersonDataXml
{
...
}


...you'll get this error.

To resolve, just add the XmlRootAttribute to your class, thusly...


[XmlRoot( "PersonData" )]
public class PersonDataXml
{
...
}



Now XmlSerializer won't get all confused.



Friday, August 8, 2008

REST vs. SOAP

I really hate this darn machine;
I wish that they would sell it.
It won't do what I want it to,
but only what I tell it.

~Author Unknown

My intent for this post is to be a 5 minute primer on the major differences between REST and SOAP. Of course, some folk may find a short post inadequate to discuss this particular topic, but hopefully many of you will find this helpful in some way. Before we get started, I'd like to point out that there are many alternatives to these two technologies that won't get discussed here, including (but not limited to) Binary XML, DCOM, CORBA, ICE, .Net Remoting, etc, each of which have their own unique advantages and disadvantages. REST and SOAP, however, are likely the more well-known and more accessible (i.e. easy to pick up).

A look at SOAP

The acronym SOAP was originally defined as Simple Object Access Protocol, but as of version 1.2 of the standard that meaning was dropped in favor of the (allegedly) more accurate Service Oriented Architecture Protocol. SOAP is an XML based protocol which provides for the passing of messages over a network, from computer to computer. In my humble opinion, the original acronym provides a more accurate description of its use today as an IT Enterprise solution for object transfer. But for the purest out there, allow me to clarify that SOAP does not pass objects over the wire, but messages.

Here's a sample SOAP request ("borrowed" from w3schools.com), which requests the current stock price for ticker symbol IBM:

<?xml version="1.0"?>
<
soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
  <
soap:Bodyxmlns:m="http://www.example.org/stock">
    <
m:GetStockPrice>
      <
m:StockName>IBM</m:StockName>
    </
m:GetStockPrice>
  </
soap:Body>
</
soap:Envelope>

And the response would look something like this:

<?xml version="1.0"?>
<
soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
  <
soap:Bodyxmlns:m="http://www.example.org/stock">
    <
m:GetStockPriceResponse>
      <
m:Price>34.5</m:Price>
    </
m:GetStockPriceResponse>
  </
soap:Body>
</
soap:Envelope>

SOAP is obviously very verbose. But it's approach is also very object-oriented, which makes it easy for most object-oriented developers to wrap their brains around. A SOAP service could be considered an object, which contains several methods that can be invoked, or properties that describe the object. If we used .Net to create a proxy class to call this web service, the C# code to invoke the GetStockPrice method might be something like this...

StockService service = new StockService();


float currentStockPrice = service.GetStockPriceResponse();


Console.WriteLine("Current stock price: {0}", currentStockPrice);


I'm using .Net here mainly to illustrate my point, which is that calling a web service looks and feels very object oriented. Even though we're not actually passing objects over the wire, it feels like we are, and so it's easy to work with.


A look at Representational State Transfer (REST)


In its most basic form, a RESTful service is "just" a URL that provides access to a resource. For example, a RESTful URL to get Apple's latest stock price might look something like this:


http://URI/CurrentStockPrice/AAPL/


Or maybe like this:


http://URI/CurrentStockPrice?AAPL


The World Wide Web is the most oft-cited example of RESTful design. Web pages support POST, GET, PUT, and DELETE, often used by RESTful applications to retrieve or modify data. Some RESTful applications add their own HTTP methods, such as WebDav, which adds PROFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, and UNLOCK.

REST is very intuitive for GET operations, and is a popular architectural choice for services on the public Internet. For example, Amazon and Google both provide RESTful interfaces to their APIs, and according to Jeff Barr, Amazon's chief web services evangelist, 85% of developers prefer Amazon's REST interfaces over their SOAP counterparts (Amazon provides both).

SOAP seems to be more easily adopted by the Enterprise, while REST is a natural fit for publicly facing Internet applications, in particular those applications where most operations are retrieving data (versus writing/posting/updating data). For example, XML results from a RESTful service seem more conducive to formatting with XSLT, simply because of the absence of the "extra" SOAP XML.

An RSS feed is a great example of a RESTful interface. I just point my favorite news reader to an RSS URI, and it's easily consumed. I can save the feed results to an XML file and easily convert it to XML using an XSL style sheet. REST is a data consumer friendly interface.


Which is Best?


Is one better than the other? I would say: hardly. That would be rather like choosing VB.Net over C#. Many developers may prefer one over the other, but you can get the job done using either tool.

On the flip side, I might recommend considering the desired feel of your application's API when choosing betwixt these two technology choices. Consider SOAP's object-orientedness vs. REST's web request based feel, and how each might impact adoption of your API.

Or, if you're using a technology like Microsoft's Windows Communication Foundation, which provides built-in support for both SOAP and REST, you won't have to choose at all.

But at least you'll know the difference.


Technorati Tags: ,,,

Monday, August 4, 2008

Twitterpated

I done did it. I went and got me an account on Twitter. I thought I'd give it a try and see what comes of it, what with all the hullabaloo about how wonderful it is. I suppose it was bound to happen sooner or later.

And so I submit to you this segment from Bambi, which I think sums up Twitter's Twitterpatedness.

Resistance is futile.

 

Technorati Tags: ,,