Has Bool flag had its day?

I was reading a collegues code review the other day and they raised the point that they didn’t understand what the new parameter in a call meant. The reason for this was the new code simply stated something like:

MyMethod(Name, Address, true)

Naming conventions means the first two arguments do a good job of conveying what they are supplying to the method. The problem with the third argument is it’s more of a statement rather than a hint to its (ahem) true meaning. The proposed solution was to swap this out for a enum; UpdateProcess.New | UpdateProcess.Edit Ok I can see how that might work, but the obvious point that seemed to have been missed is why not simply use a variable? If I rewrote the call using a variable for the Boolean wouldn’t this sort out the problem?

MyMethod(Name, Address, isNew)

Well to some extent it does, at least now the reader has some clue to the intent, however, if true==isNew what does false mean? What is the opposite of isNew? Ok you’ve read that the intent is to be new or edit, but you’ve had to discover that by some other means, the code doesn’t not convey that. You’d have to read a comment or drill down into MyMethod to understand that. This is where the (ahem..again) argument for a enum gains the upper hand. I’ll re-write it again.

MyMethod(Name, Address, UpdateProces.New)

Once again we can see what the caller wants to do a "new", whatever that is. But now the reader (assuming a decent editor) can hover over UpdateProcess and see what the alternatives are, in a binary case such as this then there are only two, previously represented by true/false. But now the reader has a chance of understanding the authors intent.

So what this long-winded blog entry is trying to say is, "do we need Boolean flags now?" I don’t think there is much need for them now, so I’ll shed a little tear for a faithful old friend and usher in more of those ugly type-space-hogging enums. I guess this is progress. R.I.P bool flag.

Upgrading Photoshop CS2 to Creative Suite 2 Standard

Decided to the a copy of Adobe Illustrator was needed to compliment Photoshop so called Adobe to ask about the options. The best all-around option was to upgrade from Photoshop to Creative Suite Standard 2 (CSS2), about the same price plus you get InDesign too.
 
So the package arrives and I start to install it. "Please uninstall the following…Photoshop CS2". Hmm, ok. "What do you want to do with your activation information?", erm spose I should keep that…why doesn’t the upgrade pack tell me what to expect?
 
So after uninstalling (and rebooting) I try to install CSS2 again. After entering the serial number, again, it asks me how I want to locate my copy of Photoshop 5 or above. Ok, I put the Photoshop CD in the drive and say, "search CD drives". "Not found". Hmm, try the other options to be faced with the same result. Grr, so I re-install Photoshop and try again.
 
"Please uninstall Photoshop" – Ha, not likely. "Continue".
"Photoshop is installed, press Quit to quit the install". No! "Continue".
"How do you wish to locate Photoshop?". "CD" – "not found", all the other options, "not found".
 
But hang on, you’ve just told me twice I’ve got the thing installed and now you can’t find it!!! So I hit browse and lead the horse to the water. Hurray, it worked off we go. Good grief and I thought installing Quark software was a pain in the seating area. So the trick seems to be, don’t uninstall Photoshop CS2, no matter how much it begs you to. Although, I’ve yet to start using it earnest so who knows what awaits me.

Mocking services in Unit Tests

I recently posted the following; Unit Test Mocking…


I’m currently looking at several Mocking tools to try and break various component dependancies when unit testing. So for example I want to unit test MyObject.SayHello(arg1) but that uses MyDataService.GetData(Request). When I unit test I don’t want to actually want to invoke MyDataService but simply assume a return value. That way I can unit test only MyObject and not worry about any incorrect behaviour (or setup problems) from MyDataService.

Looking at the options the majority of the Mocking objects work in the following fashion:

MyUnitTest()

MockObject("MyDataService.GetDate", "MyInputValue", "AssumedReturnValue");

MyObject.SayHello("Hello");

…..

What I really dislike about this approach is that to write the unit test I need to know alot of information about the services MyObject is going to call, I think this is wrong for a couple of reasons. 1. I wouldn’t assume the author of the unit tests knows anything about the services that will be called, especially in when using Extreme Programming and/or a second person other than the code component author is writing the tests 2. If the service changes you have a maintaince headache of revisiting all the unit tests to change their expected values.

I’ve got some ideas about;

a) having a centralised map of in’s and out’s (maybe with special codes in invoke real components)

<MyObject><UnitTestTypeA><MyDataService/>..

<MyDataService><UnitTestTypeA><in>bla</in><out>blabla</out>…

b) decorating the methods with example values

[UnitTestTypeA; In=bla;out=blabla]

MyDataService.GetData

c) the service components mock their own objects and the clients asks for all the mocks, so the code looks something like

MyUnitTest()

MyObject.GetAllMocks("UnitTestTypeA")

MyObject.SayHello("Hello");

i.e. would require reflection or interfaces an extra code in the components solely for Mocking

d) some combination of the above


I had a interesting reply from Joe Rohde, who seems to have some inside knowledge at Microsoft, that they are looking into producing something similar for a future realease of Visual Studio. That’s given me the push to look at implementing (c) probably using using something like reflection rather than interfaces that way it should be possible to maintain some form of map association with the actual component rather than implement code into the component. The first hurdle I can see is how to mock objects that are not simple types and do not support serialization. 

DotNetNuke and Stylesheets

My Dad has recently started subscribing to a portal site for his business and was asking about how to style the site correctly. After a cursory look I realised that the site was in fact a DotNetNuke portal. Fine I thought, just write a new skin and off we go. However, in their great wisdom the portal administrator had switched off any ability to add/change skins, so we’re left with the default skin. The problem is that the default skin is churning out a terrible mixture of structure and layout HTML making it almost impossible to style correctly. I’ve really struggled to make them understand why their portal is currently so terrible because of it. This company is one of those companies that give the IT industry a bad name. They pick up a product, which is free, and take money from unsuspecting customers but provide them with a rubbish result because they cannot either understand or be bothered to use the tool properly in the first place. I’m sending them a link to a What is CSS FAQ in the hope they can at least read about CSS.