I am a duct tape programmer

We all know what duct tape programming is. I am one of them. I am no way close to Jamie but ya, I will make sure that the cart keeps running and crosses the finish line in time, whatever it takes. All the programming practices, patterns, Agile, waterfall, yada yada, are thrown out of the window when we have to make something complicated in a very very very, did I mention very, short deadline.

All the best programming practice gurus… no hard feelings, Peace.

Happy Programming

Reusing types with Visual Studio Service Reference.

I am sure this is something many folks would have come across by now. But what the heck, I thought of adding some more crap on the internet. So, this is what I want to do, I have a shared library called MySharedLib.dll. I have added a reference to it from my Console Application project. Now I want to add a WCF Service reference to my application, but the service internally uses MySharedLib.dll too. So you say whats the problem?? For newbs, if you add a reference to such a service without doing “something” in Visual Studio, the proxy generated would have defined the same type in its namespace. This type would be incompatible with the type which is in MySharedLib.dll. Enough blabbering, here is some code

public ConsoleApplication3.ServiceReference1.Assignment[] GetAssignments(ConsoleApplication3.ServiceReference1.User authenticatedUser) {
return base.Channel.GetAssignments(authenticatedUser);}

public ConsoleApplication3.ServiceReference1.AppFolder[] GetAppFolders(ConsoleApplication3.ServiceReference1.Assignment userAssignment) {
return base.Channel.GetAppFolders(userAssignment);

The above classes like Assignment, User, AppFolder are not the ones from MySharedLib.dll. They are generated for the proxy by Visual Studio. If you try to assign this type to a variable of type in MySharedLib.dll they would obviously be incompatible. If you want Visual Studio to reuse the types in a shared library in its proxy do the following –:

In your project to which you need to add a service reference, add a reference to the shared dll you need to reuse.
On Add Service Reference dialog, click Advanced,

Capture1


And this,

Capture2



Happy Programming!

Avoiding Temporal Coupling

Ahh, I just love getting back to my blogging time. Its been a busy month with lots of caffeine and code. But that's divine isn't it? So, getting back to basics, I hate coupling in my code, umm.. Everyone does. I just wanted to highlight one not so apparent coupling seen all over the “bathroom wall of code”, Temporal Coupling. For the definition freaks, Temporal Coupling is when your functions need to be called in a specific timeline/order to get the desired output. Well, look for yourself,

internal void BeAGuitarist()
{
BuyAGuitar();
TuneGuitar();
StartRocking();
}


To BeAGuitarist, the order in which the functions are called inside it are important. If you are developing an application framework which will be used by gazzilion developers to build their applications, how would you instruct each one of them to follow this order. Sooner or later it will get out of control and you would get mails like your framework sucks to the core.

One of the primary reasons for Temporal Coupling is global variables. In the earlier snippet, probably there is a variable “guitar” which is being modified by each of the functions. If we can localize that variable and pass it as an argument to the functions, we eventually force the usage in a particular way. The above code can also be written something like this,



internal void BeAGuitarist()
{
BuyAGuitar();
TuneGuitar(guitar);
StartRocking(tunedGuitar);
}


I hope you get the point, if not, just fuck it, I am too cynical about many things in life!

Happy Programming!