The Daily WTF
There used to be the best website, called the Daily WTF, out there where as a developer you could submit the most ridiculous gems of "code" you happen to stumble across in your everyday existence...
Reading through the various posts and comments used to provide me with some light hearted relief knowing that we walk amongst some very "special" people that call themselves developers.
The site appears to no longer exist or has change guise. Something about it's not PC to ridicule bad developers and the horrible code they write. Something about the fact that as developers we should take the time to understand their point of view and instead of shaming the code for the waste of 1's and 0's that it is we should make a concerted effort to mentor these people so that they could learn .... I say to hell with that!
Today I received a pure gem of an example and had the site still be around it would've won the award for "best" submission of the day without a doubt.
To protect the guilty, for fear of legal action, names have been left out and actual data has been changed, but the concept remains.
I am consuming a web service published by an external partner. Being a follower of contract first development I go get the Wsdl and from this I generate the XSD. This is my contract, my interface, that I am going to work against.
The XSD states that approximately 100 odd fields of various types including enums are all required. xs:nillable = false. Meaning that before my Xml that I construct can be considered as valid it has to supply data of the appropriate type for each and every field. Nice. Except I don't have all the data.
I then requested that they update their schema to make fields that are optional exactly that optional.
The response I got would've been the submission to daily WTF.
Wait for it, this is classic ...
Just use "" for strings and pick any value from the list of allowed values for the enums.
My god!
Ok now bare in mind that this is for a financial system, so the integrity of the data is key here, else can you spell L A W S U I T ...
So I mention to the other developer that guessing values is a really bad idea and the response from this was
"Why? Just consume the service in Visual Studio and let it default the values you don't supply."
So for shits and giggles sakes I did as he suggested. I built a simple Console application, consumed his service and watched in "amazement" how Visual Studio proceeded to create a bunch of classes for me. I then set only the firstname and surname properties of his contact object.
Before passing this object to the web service I added a little code to serialise this object to Xml. This is in a nutshell what the kind folks from Redmond are doing behind the scenes anyway, just to see what would actually be submitted to the service.
The result was a laugh; I got a contact with the correct name because this is what I supplied but the fun came with how VS defaulted all the lookups to the first value from the enum.
So I had a white male who was another contact's mother, who lived in Zimbabwe yet had nationality as Domestic and citizenship as South African. It also defaulted numeric values to 0, so we had his age as 0, but dates were set to 1901.01.01, so his birthdate element was set to some other date not matching up to his age at all.
Here's a news flash buddy, firstly not all of us use Visual Studio to consume web services; Ever heard of SOAP? Know what SOAP is other than the stuff you wash (hopefully) with. The default stuff that Visual Studio generates might be ok for simple services and you could probably get away with it 75% of the time, but you really need to have a remedial grasp of what is happening behind the scenes.
This is one of the major problems I have with how easy Visual Studio and .NET is making things, it allows a person who has no fundamental grasp of the concepts to generate code via a "paint by numbers" approach. In a similar manner I see developers today going mad with allocating memory (managed and unmanaged) and not disposing stuff because they assume .NET will cleanup after them because they did not take the time to understand the basic concepts of what is happening behind the scenes. But this is the subject of a whole other rant best left for another post.
Decorating all the methods of an existing system with the [WebMethod] attribute and returning your ADO.NET datasets does not a service orientated system make.
I wouldn't be surprised if this guy was a VB developer too 