Thursday, May 29, 2008

Introverted Programming: File Oriented Architecture

Meet the new kid on the block: FOA - the File Oriented Architecture.

FOA contracts are simple - applications connect with each other assuming that the counterpart can be found in a certain location. In a pseudo-code contract would look like: "three folders up - two steps right - two folders down - get Foo.Moo instance". FOA has vendor support - in a sense, Microsoft Web Site projects are examples of FOA approach. FOA is a further development of the KISS principle - the KISS of a Web 2.0(beta) era, KIverySS.

FOA is a very clean and controllable way to code reuse. "In-depth understanding of FOA principles" looks good in resume (it has "Architecture" in it!). It is much easier concept to understand than SOA or REST so any hiring manager will be on the same page with you. Document-Driven Development tools, such as wordUnit, can be used to ensure binding links accuracy within a Continuous Integration process.

FOA beginners operate with full paths, like

AdminConsole console=
new AdminConsole("C:\Documents and Settigns\joe\MyDocuments\Foo\Moo\AdminConsole.aspx");

But true master knows the power of relative paths:
AdminConsole console=new AdminConsole("..\..\..\Foo\Moo\AdminConsole.aspx");

This way the application deployability is much higher. Also the master will encapsulate values in the configuration file where they can be easily changed if any silly developer would suddenly change structure of the bound application. Imagine the flexibility of deployment application over web-farms and clustered servers. We can construct relative paths to a relative locations - the possibilities of combinations are endless.

Setting up (or getting back) a default browser

Once you installed Firefox and made it default browser, it will be tricky to let Internet Explorer step back in. It is formidable achievement - to defeat Microsoft own on it's home grounds, but it may be a little bit annoying, especially for a debugging.

So here is how you can help this poor Microsoftee to gain its glory back (system and Visual Studio settings are independent of each other):

1. For the system (at least for Win XP):

Control Panel -> Add or Remove Programs -> Set Program Access and Defaults -> Custom (this double chevron on the right side ) -> choose a default Web browser

Just be aware that the Firefox, pertinacious it is, will add itself back to the Quick Launch menu as soon as it will become default again.

2. For the Visual Studio:

First, you have to switch to any aspx (or ascx) layout file.

"File" menu -> "Browser with..." -> set a default browser of your choice.

Enjoy the powers of "Lord of the Windows".

P.S. All is intermingled in this world. If you tried to get yourself rid of that annoying Windows Update "Reboot Now - Or Die From Chafing" popup - beware, the Automated Update service will restart after Internet Explorer is made default browser for the system and continue to nag you.

Sunday, May 25, 2008

Mac vs. PC - so what's the deal?

It is interesting that PC-world haven't got back to Apple for those Mac vs. PC commercials (Update: I was wrong - they did). Partially, I guess, it is because there is no such monolithic entity as evil PC empire - so the campaign  is more like "Mac vs. Everybody". But there is another side of that: Apple has never worked harder in favor of PC. Put all commercials together - what do you see?

Doesn't it look like Apple is actually arguing for the choice


One could retort that ads can easily impress turtle-neck-sweater-wearing-latté-drinking designer dudes, who run their Photoshop on Macs anyway. And that's cool - I'd trade my PC for Mac any time if I would be rendering pictures all day. But the corporate CIOs do not need to be reminded about PC troubleshooting - they trust that with their engineers PC problems are easy come and easy go.

So as a result the ads, witty they are, actually developed totally undesired by Apple perception:


OK, OK, not only artists run Macs - I know a whole bunch of deadly efficient (.NET/Ruby/C++/Just-Name-It) developers who use MacBooks. But interesting, what are the most popular applications for Mac, aside of Opera browser? I dare to surmise Boot Camp or Parallels. I even bet that you would find them on a majority of die-hard Maceteers' computers.

And corporations are evil, anyway, so who cares about what those CIOs think? It's all about users and their freedom! I support Jeff Atwood in his quest for the fair product.


And another omission from Mac marketers - Mac is portrayed as a leisure-time computer (I just afraid to think where that Japanese-camera girl took a picture from). C'mon! Don't you have something else to do after work? Or have friends who you can listen instead of iPod?


And at the bottom line - Mac compares itself with PC, but in reality PC has no face. It's not fair. When we are to compare hardware with hardware and soft with soft so we should do this:

compare personality:


or efficiency:

Also it all was happening already - in 1996. Where the Apple Inc. ended up shortly after?

P.S. Mac is OK, really. As well as PC. And there is no real difference between them to be zealot about.

Saturday, May 24, 2008

Pre-manufactured AJAX

Ajax-enable your web-server within minutes. No skill required.

Friday, May 16, 2008

.NET Framework 3.5 SP1 Beta 1 - use some non-beta stuff today

One of the aspect of shiny tomorrow is going to be Ajax Script Combining Support - very nice feature no doubt it will be. If you ever fired the Firebug while debugging ASP.NET Ajax Control Toolkit (which I like more and more every day), you probably saw quite a few scripts being pumped up from the server. This is how the load looks with just one Autocomplete Extender:

But fear not - you don't have to wait for the full Service Pack release and you don't have to suffer with crippled Betas. The script combining functionality is already available in a stable form - through the ASP.NET Ajax Control Toolkit. ToolkitScriptManager class inherits from the standard ScriptManager and efficienlty eliminates multiple requests, combining scripts which express willingness to be combined in the form of a ScriptCombineAttribute.
This is the same page with TooliktScriptManager replacing a ScriptManager:

We saved a quarter-second for page with just for one control - how much Ajax-junkies will gain?

Now back to the Service Pack 1. Initially I though that ASP.NET team just ported a brilliant Toolkit-guys idea into the upgrade. But from the preview it looks like they did their own ScriptManager extension. New ScriptManager seems to provide more detailed adjustment while TooliktScriptManager is much simpler and elegant. It is too early to say and there is no way I would install Beta from Microsoft again.

.NET 3.5 Service Pack Beta 1

Welcome to Microsoft Labs where the future is being made today!

Hewlett Packard Notebook wireless card problem

I can consider computer new if it's under the year old, can I? I've been using my HP Pavilion dv6000 for 7 or 8 months when wireless card went crazy. It wouldn't turn on for a few days, when suddenly resurrect for a day and get back to abyss  for weeks.

Research has shown that problem is so common for this particular model (every other person referred to a "cheap crappy parts") that HP decided to bestow upon its unlucky customers a Limited Warranty Service Enhancement (the model list has grown since my last visit :).

But I didn't realize how common this problem, until I sent the notebook for repair. Judging by UPS tracking, the shipment was delivered to HP at 9AM May 15th and I've got my machine back on May 16th morning. So they barely had one workday to deal with my machine. I doubt that my case was handled by a super-dedicated employee who forfeited his coffee breaks in order to make me happy. There were scarcely enough time to even restart Vista couple of times*, forget the diagnostics. So looks like they have some conveyer when they just replace whatever they do, without even turning machines on, and ship them back.

* I wouldn't be so grumpy about HP if they did not force me to buy the preloaded Vista Home in the first place and, even worse, forced me to replace my heavy-loaded XP Pro with the Vista again before the repair. Otherwise they wouldn't even touch it, they said.

Wednesday, May 14, 2008

Fixing Continuous Integration build for a .NET 3.5 project

My CI build fails with the following error:

C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(1993,9): error MSB3091: Task failed because "sgen.exe" was not found, or the correct Microsoft Windows SDK is not installed. The task is looking for "sgen.exe" in the "bin" subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A.
You may be able to solve the problem by doing one of the following:
1) Install the Microsoft Windows SDK for Windows Server 2008 and .NET Framework 3.5.
2) Install Visual Studio 2008.
3) Manually set the above registry key to the correct location.
4) Pass the correct location into the "ToolPath" parameter of the task.

The research has brought quite a few posts about this problem, with Dan Händevik's being the most helpful and MSDN Forum's - the least (surprise, surprise). Unfortunately the proposed manual solution didn't work for me. I blamed it initially on my ambiguous x32/x64 server setup but all my attempts to trick the MSBuild didn't succeed and it kept reproducing that annoying error. I even tried to synchronize NAnt configuration with supposed SDK paths (BTW - there is an excellent post about tricking your NAnt 0.85 to run .NET 3.5 assemblies).

The exception itself is actually confusing - as it appeared afterwards, the mentioned registry key was still missing while build was running OK. My guess that it is hardcoded  somewhere but it's hardly worth digging into the code with Reflector.

The only solution which eventually helped was to install the Windows SDK for Server 2008 and .NET Framework 3.5. I was confused by the download's title initially (our build runs on the Windows Server 2003) - but SDK didn't seem to harm anything (at least not yet). The installation is much smaller than suggested VS 2008 and now build is healthy (it is still failing for different reasons but that's another story - at least it passes the assembly stage).

Tuesday, May 13, 2008

ASP.NET Ajax Toolkit - getting a key-value pair from the auto complete extender

Autocomplete Extender is a nice control, no doubt. And free. I didn't check earlier versions but current solution uses JSON web services and pretty fast.
Originally the Autocomplete Extender lacked very important functionality - ability to operate with key-value pairs. If you think about that, the Google search auto complete serves its purpose - the resulting string IS the value which is important for the postback, but it is scarcely the case for the 98% of non-search applications. We need control to mimic dropdown list - so gimme ya money let me keep the value for the entered text! Such a functionality was added some time ago but regretfully the feature was left undocumented.

You need to make few small changes to the original example: add JavaScript handling on the client and modify Web Service to return more sophisticated array. The Web Service method has to generate the list with the items in {"First":"<Name>,"Second":"<Value>"} format. E.g.

{"First":"Nissan Oakville","Second":"34AF44d2-1190-f489"} 
Method AutoCompleteExtender.CreateAutoCompleteItem(name,value) can help to create proper format.

Page looks like this:

<script type="text/javascript" language="javascript">
function GetCode(source, eventArgs )
document.getElementById("hCode").value = eventArgs.get_value();

Enter Manufacturer: <asp:TextBox ID="txtManufacturer" runat="server"/><input name="hCode" type="hidden"/>
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
And this is a full web service code:
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AutoCompleteService : System.Web.Services.WebService

public string[] GetCompletionList(string prefixText, int count)
List<string> names = new List<string>();
using (SqlConnection conn = DbGateway.GetConnection())
SqlCommand cmd = new SqlCommand("GetManufacturersByPrefix", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@prefix", prefixText));
cmd.Parameters.Add(new SqlParameter("@count", count));
using (SqlDataReader reader = cmd.ExecuteReader())
while (reader.Read())
string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem
return names.ToArray();
As a result if postback is required, the hCode element will hold the value, matching the text from txtManufacturers box and can be extracted from Request.Form collection.

P.S. Microsoft has to apply some serious ass-kicking to their Documentation Generation (or whatever) Department. Poor MSDN documentation and samples are unbearable and this tradition seems to infect the Microsoft-flavored open source community.

Saturday, May 10, 2008

Pimp my ride

Being contracting for a little while I've noticed that I am going through the same routine over and over again, setting up my new workhorse computer at yet anther work place. I realize those thing help me make less efforts while being same productive. Those are my typical steps, what are yours?

1. Simplify Windows.

I was lucky so far to not encounter companies who adopted Vista as their development platform. It's either everybody around is smart or those unlucky ones die faster than first candidate would answer their recruiting ad. So no experience with Vista whatsoever.

  • Turn off the Appearance Effects.
  • Set folders view to Classic Windows.
  • Purge all junk from the Start Menu (or at least dump it in some "Miscellaneous" subfolder). The Startup folder should be empty!
  • Drug all the important shortcuts to the desktop - Visual Studio, SQL Management Studio, IIS Manager, .NET Reflector, WinMerge, Virtual PC, Remote Desktop and whatever you need for daily work. And clean up everything else: IE, Outlook, MSN, My Network Places...
  • Being younger and more radical I used to turn on the Classic Windows Schema but compared with Vista XP Schema suddenly looks OK.

2. Firefox - surprisingly Firefox is still not a part of the default PC image.

  • Reorganize the toolbar - make buttons small, add "New Tab" icon and move Bookmark Toolbar up there.
  • Web Developer, Firebug - if you didn't try it yet - get them right away. (the OEM version will do) and Wikipedia Lookup addons.
  • .NET Reflector - Isn't this guy a marketing genius? When you start Reflector, it's all you see in the task bar - "Lutz Roeder's .NET Re...", and it eventually will burn into your mind, who you should thank for this excellent tool.

4. Tortoise SVN. There are two kind of shops around - those with Team System and can't get into rehab and those who don't care (those with Visual SourceSafe do not really care). So Subversion emerges eventually. There are another good tools, I know, but I have to encounter Git-enthusiast on my journey to include it to my list.

5. Most recent addition - WinMerge tool. Friendly, simple, fast. Free.

6. Pimping up Visual Studio.

  • Remove stupid start screen and perverse visual effects. They still are in the VS 2008 - who honestly needs them, considering the IDE speed is so precious?
  • Resharper (if I can get it). It is absolute necessity for VS 2005 and I can't wait when Version 4.0 will bring the Light to the VS 2008.
  • Two new nice additions to the VS 2008: Visual SVN and Source Outliner power toy. The first is not free but is absolutely worth it's $50 price tag. The second is helpful for code reviews (especially if code is polluted with #region directives).
7. CCleaner is the best contractor's friend. Clean it up daily and go nuts at the end-of-service time to keep your privacy and employer decency.

This list should do. Completing it gives me a feeling that my first day at the new place wasn't completely wasted.

Friday, May 09, 2008

Code quality - #region directive is evil

It is, you should agree. It pollutes the code making it very difficult to read (who remembers the hotkey to Expand All?). And it doesn't help a bit.
Even if it seems to be a good idea at the time, think of how painful it will be to read the code when you (or another poor bastard) will be asked to make changes few months down the road (I barely can keep my last-week code in mind).
If one is tempted to use #region then it most likely means that a) module has grown too big to manage b) there are parts of code in the module which are irrelevant to other parts. And usually a) is directly caused by b). It doesn't mean that methods or properties from another region are completely unrelated - they just obscure reading. And #region addresses this issue very poorly. There is no reason to keep all this code in the same module - split it. It will allow to read two related pieces of code simultaneously, switching with ctrl+tab instead of scrolling back and forth, and it will make a nice, clean, better organized code. And if you think that it is too minimalistic - read about "Perfecting classes and small methods"
Code cohesiveness is the best weapon against monstrous modules. The UtilModules are evil too and I created a lot of them (and keep doing it) to know how bad they are :). UtilModule is kind of unavoidable for junk storage but still there is no excuse for the #region Database stuff - separate it to a DbUtilModule!

Sunday, May 04, 2008

ASP.NET Ajax control toolkit vs. VS 2008

If you plan to use some Ajax in your ASP.NET web project, even if you not sure, - just make an Ajax Control Toolkit installation your very first step. In fact - do it as the very first step for any project, just in case - drug any control to the default.aspx. In 50% cases you'll get the error message "The operation could not be complete. Invalid FORMATETC structure". Very informative, and Google doesn't help much.

It is scary that there are Microsoft very own MVP's among frustrated posters and there is no single question answered. Oops, my bad, - there are answers; this one worked (the only): "Scrap your project and start new one, making the Toolkit test your very first step. If failing again - start new project". Nice. BTW - it is the same for VS 2005, so problem was around for a while. So basically, if you do not wish to spend, like me, half an hour in swearing, while porting semi-complicated structure to the new project, - just be a smart boy and try the Ajax Toolkit as a first step.

Another sour disappointment in Microsoft quality - the Microsoft-style open-source. Looks like a bunch of MVP's, who herded up for ASP.NET Ajax library initially, lost their interest. I haven't seen any visible activity on the site for a while and the latest installation instructions happily ignore even Orcas. That's why I am a little bit skeptical about all this new buzz. Smart boys are playing with their new toys - good for them, but we - mortals down here, are supplied from the Microsoft soulless production floor (where just drones are). So you should either do not care or try Toolkit (or MVC, or Dynamic Data), starting your project, just in case.

© 2008-2013 Michael Goldobin. All rights reserved