Friday, September 26, 2008
#
Steve Smith has posted a couple of interesting probability problem solvers on his blog recently. His most recent one is a twist on the Monty Hall problem. I mentioned the Monty Hall problem and its solution in an earlier blog entry of mine, For Some Probability Problems, Seeing Can Be Believing:
When facing a particularly tough probabilty problem sometimes it helps to sit down and draw out the possible outcomes for the given scenarios. In doing so, things that may otherwise seem very complex boil down to a very apparent solution or explanation.
A great example of simplicity through diagraming is the Monty Hall problem, which goes like this: You are a contestant on the TV game show, Let's Make a Deal and are presented with three doors. Behind one door there is a luxury car. Behind the other two doors there is a poster of a car. The game show host asks you to pick a door. After choosing one, the game show host reveals one of the other doors that has a poster behind it and then asks you if you want to change your door choice to the other unopened door. What is the best strategy?”
The answer is that you should change the door you had selected, because there's a 2/3 probability that the door you did not select houses the luxury car. In other words, there is a 2/3 probability that the door you picked has the remaining poster. The solution seems backwards. It seems paradoxical that the door the host reveals to have a poster of a car could have any influence on your initial selection. But if you sit down and draw out the various probabilities you can see that there's there are more good outcomes if you make the switch than if you hold fast to your initial choice. The following diagram was created by Rick Block; here, instead of a poster of a car you get a goat. Same difference.

Steve's most recent puzzle asks what would happen if instead of a single contestent in the Monty Hall problem there were multiple participants:
I take 3 plain envelopes and put a $100 bill inside one of them, seal them, and give one to you, one to Bob, and one to Carrie, at random. Then I randomly ask one of you to open an envelope - for the sake of argument let's say I choose Carrie. Carrie opens her envelope to reveal that it is empty. Now I offer you the choice to trade envelopes with Bob - should you trade? And now I ask Bob the exact same question. Should he trade?
As written, Steve's problem isn't that interesting. If he is randomly choosing one envelope to open then there is no advantage to be gained by changing or not changing your envelope. Now, if Steve were to reword the problem as follows (as I believe was his intention), then things are a bit more interesting:
I take 3 plain envelopes and put a $100 bill inside one of them. I then let you choose one, and then give the other two to Bob and Carrie. I then open one of the envelopes (Carrie's or Bob's) knowing that it is empty. Now I offer you the choice to trade envelopes with Bob - should you trade? And now I ask Bob the exact same question. Should he trade?
There is a big difference between these two questions. In the first one, everything is random; in the second one, the host (Steve Smith) knowingly opens one of the envelopes that is empty. It's also important that the host is forced to open Bob or Carrie's envelope, and cannot attempt to open yours.
The answer to this problem can be worked out the same way as the traditional Monty Hall problem - by putting pen to paper and drawing out the probability tree, although I used the name Cal instead of Carrie. (See the full size image...)

As you can see, your odds are maximized if you get your hands on your contestant's envelope, while your opponent's best bet is to keep his envelope. Therefore, whoever gets to make the final change is the person with the best odds.
Another tool for determining how a probability puzzle works out is through empirical means. You can oftentimes write a terse program that simulates the problem at hand thousands of times and tallies up the various outcomes. I created such a program in C#.
1 for (int iter = 0; iter < ITERATIONS; iter++)
2 {
3 int moneyPos = rnd.Next(3);
4 int bucketChoice = 2;
5 int openDoor = rnd.Next(2);
6 if (moneyPos == openDoor)
7 openDoor = 1 - openDoor;
8 int oponentsPos = 1 - openDoor;
9
10 bool makeSwap = rnd.Next(2) % 2 == 0;
11 bool otherContestantMakesSwap = rnd.Next(2) % 2 == 0;
12
13 if (makeSwap)
14 {
15 tmp = bucketChoice;
16 bucketChoice = oponentsPos;
17 oponentsPos = tmp;
18 }
19
20 if (otherContestantMakesSwap)
21 {
22 tmp = bucketChoice;
23 bucketChoice = oponentsPos;
24 oponentsPos = tmp;
25 }
26
27 // See if we won
28 if (bucketChoice == moneyPos)
29 {
30 if (makeSwap && otherContestantMakesSwap)
31 numberOfWinningsWhenSwappingAndContestantSwaps++;
32 else if (makeSwap && !otherContestantMakesSwap)
33 numberOfWinningsWhenSwappingAndContestantStays++;
34 else if (!makeSwap && otherContestantMakesSwap)
35 numberOfWinningsWhenStayingAndContesstantSwaps++;
36 else
37 numberOfWinningsWhenStayingAndContesstantStays++;
38 }
39 else if (moneyPos == oponentsPos)
40 {
41 if (makeSwap && otherContestantMakesSwap)
42 numberOfContestantWinsWhenYouSwapAndContestantSwaps++;
43 else if (makeSwap && !otherContestantMakesSwap)
44 numberOfContestantWinsWhenYouSwapAndContestantStays++;
45 else if (!makeSwap && otherContestantMakesSwap)
46 numberOfContestantWinsWhenYouStayAndContestantSwaps++;
47 else
48 numberOfContestantWinsWhenYouStayAndContestantStays++;
49 }
50 }
51
52 // Summarize results
53 Console.WriteLine("Percentage of Wins When Swapping and Contestant Swapping: {0}", Convert.ToDecimal(numberOfWinningsWhenSwappingAndContestantSwaps) / Convert.ToDecimal(ITERATIONS));
54 Console.WriteLine("Percentage of Wins When Swapping and Contestant Stays: {0}", Convert.ToDecimal(numberOfWinningsWhenSwappingAndContestantStays) / Convert.ToDecimal(ITERATIONS));
55 Console.WriteLine("Percentage of Wins When Staying and Contestant Swapping: {0}", Convert.ToDecimal(numberOfWinningsWhenStayingAndContesstantSwaps) / Convert.ToDecimal(ITERATIONS));
56 Console.WriteLine("Percentage of Wins When Staying and Contestant Stays: {0}", Convert.ToDecimal(numberOfWinningsWhenStayingAndContesstantStays) / Convert.ToDecimal(ITERATIONS));
57 Console.WriteLine("");
58 Console.WriteLine("Percentage of Contestant Wins When Swapping and Contestant Swapping: {0}", Convert.ToDecimal(numberOfContestantWinsWhenYouSwapAndContestantSwaps) / Convert.ToDecimal(ITERATIONS));
59 Console.WriteLine("Percentage of Contestant Wins When Swapping and Contestant Stays: {0}", Convert.ToDecimal(numberOfContestantWinsWhenYouSwapAndContestantStays) / Convert.ToDecimal(ITERATIONS));
60 Console.WriteLine("Percentage of Contestant Wins When Staying and Contestant Swapping: {0}", Convert.ToDecimal(numberOfContestantWinsWhenYouStayAndContestantSwaps) / Convert.ToDecimal(ITERATIONS));
61 Console.WriteLine("Percentage of Contestant Wins When Staying and Contestant Stays: {0}", Convert.ToDecimal(numberOfContestantWinsWhenYouStayAndContestantStays) / Convert.ToDecimal(ITERATIONS));
I set ITERATIONS to 50,000 and let 'er rip. The following output confirmed my initial assumptions:
Percentage of Wins When Swapping and Contestant Swapping: 0.08266
Percentage of Wins When Swapping and Contestant Stays: 0.16618
Percentage of Wins When Staying and Contestant Swapping: 0.16482
Percentage of Wins When Staying and Contestant Stays: 0.08318
Percentage of Contestant Wins When Swapping and Contestant Swapping: 0.16754
Percentage of Contestant Wins When Swapping and Contestant Stays: 0.08386
Percentage of Contestant Wins When Staying and Contestant Swapping: 0.08262
Percentage of Contestant Wins When Staying and Contestant Stays: 0.16914
As you can see, your chances of winning are best when you swap and your contestant stays or when you stay and your contestant swaps - namely, when you get your hands on your contestant's envelope. Your contestant, however, does best when he hangs onto his envelope, either by having you both stay or both change.
Friday, September 19, 2008
#
Every couple of weeks or so I seem to have a need to transfer (or receive) a relatively large file to another colleague or client. It might be a database zipped up into a 50 MB file, artwork totalling hundreds of megabytes, or various DLLs and source code. Over the course of my career I have used the following techniques for transferring data:
- E-mail - the most straightforward technique for sharing data. The major con is that many email providers reject attachments over a certain threshold, usually in the 2-10 MB range. Also, e-mail is inherently insecure, making it a non-ideal medium for transferring sensitive data like passwords, credit card numbers, social security numbers, and so on.
- Upload/Download from a Website - if you have write access to a website you can always upload the data to share and then send a URL to the file(s). The downside here is that you need a website. Security also requires a few extra steps - you need to have some mechanism to only allow the intended recepient from downloading the article.
Side story: Back in 2002 Microsoft released Web Matrix, which later became Visual Web Developer Express Edition. Prior to announcing the release Microsoft and asp.netPRO Magazine asked me to write an overview of the tool to be included in the asp.netPRO edition that came out right when the product was released officially. There were a group of other ASP.NET folks at the time who also knew about this project and were invited to review my article. I distributed it by putting the article up on a website and provided this group a link to download the article. A couple days later I left for a short vacation during which I did not check e-mail or phone messages.
The day I left town one of the reviewers leaked the article to Neowin.net, which linked directly to the URL on my website. Shortly after the link was published on Neowin.net I started getting e-mails and phone calls from Scott Guthrie asking me to take down the link. Of course, I did not get these messages until a few days later upon return from my vacation.
I never did find out who leaked the link/article. I guess it didn't really matter in the end, and it wasn't the article on my server that caused the leak as someone else sent in the link to Neowin.net and they could have just as easily sent the Microsoft Word document. But still, I was rather red-faced when having to explain to the guys at Microsoft why the article was accessible to anyone on the Net and why it took so long to get the article down once it had been compromised.
- Use a Third-Party Service - there are a plethora of web-based services that are built to allow large files to be transferred between two individuals. Most work by you uploading a file to a site, where it is stored temporarily. You then e-mail the recipient a link to download the attachment. I have used the free service TransferBigFiles.com many times and heartily recommend them. You could also use DropBox and place the file to share in the Public folder. The benefit of this approach is that you don't need a website; however, the security concerns remain. In fact, you might consider the security concerns even (slightly) greater because you are now adding an intermediary into the equation (the folks at TransferBigFiles.com or at DropBox).
- Physically Deliver the Data - the most secure option is the physically deliver the data - put it on a thumb drive or burn it to a DVD and then mail or hand deliver the data. This approach takes the most work, but is the most secure, especially if you hand deliver the data. And if you are transferring extremely large amounts of data - terrabytes, let's say - this approach would likely be the fastest.
I used this approach 8 years ago when transferring large amounts of information between myself and a publisher. At the time I only had dial-up access. When the publisher needed to send me several hundred megabytes worth of materials - mostly artwork from previous editions - it was more efficient to mail me a CD. I also had a student in one of my Web Services class, must have been four years ago or so, whose company was running computer simulations that would output several GBs worth of data per test run. To send the day's test data to another facility they would plug in an external hard drive, copy over the data, and then use a mail carrier to overnight deliver the drive. I wonder what techniques they use today.
How do you share large files with others?
Monday, September 15, 2008
#
Remember when people used to debate what search engine was the best among the bunnch? Do you remember back in the day when Yahoo! differentiated itself from other search engines by having actual human beings catalog, summarize, and rate large swaths of the World Wide Web? Today, search is a commodity. It's ubiquitous. Web surfers expect there to be a search box and expect accurate results returned in the blink of an eye. Because of these expectations, it's now more important than ever that your website offers search. I don't care if the site has only five static web pages that only get updated once in a blue moon, you still need search.
The good news is that Google offers free tools for quickly and easily adding search to your site. With Google's Custom Search Engine (CSE) you can add search to your site within a matter of minutes. All it takes is configuring a few settings and then copying and pasting a snippet or two of HTML and JavaScript into your site. A couple of months ago I used CSE to add search to this blog. You can find the search interface in the upper right hand corner of every page or by visiting the Search page.
To learn how to add a search engine to your site using CSE check out my latest article on DotNetSlackers: Implementing Search in ASP.NET with Google Custom Search.
Site Note: Another technique for making your site more searchable is to create an OpenSearch provider. By adding a simple XML file to your website you can have your site searchable through the search box that's baked into the user interface of browsers like Internet Explorer and Firefox. Learn more about this technique by reading: Helping Visitors Search Your Site By Creating an OpenSearch Provider.
Tuesday, September 09, 2008
#
I try to keep this blog tightly focused on technical issues, but I wanted to share this happy bit of news: on September 1st my wife gave birth to our daughter, Alice Mitchell. Mom & baby are healthy and happy.
If you'd care to read a bit more about this, I've blogged about it on my personal blog, ScottOnLife.com: Then There Were Three.

My Toolbox column in the September 2008 issue of MSDN Magazine is avaiable online. The September issue examines:
- LINQPad - A free stand-alone LINQ editor/tester created by Joseph Albahari, author of C# 3.0 in a Nutshell. LINQPad is like SQL Query Analyzer, but for LINQ.
- Blogs of Note - Rob Waling - Rob is an ASP.NET developer, independent contractor, and micro-ISV. Many blogs examine the latest coding tips and tricks, but Rob's blog is unique in that it focuses more on the business and interpersonal aspects of being a successful developer.
- Logging Libraries - There are a number of logging libraries available for .NET. This issue of Toolbox looks at two popular libraries: the Enterprise Library and log4net. The Enterprise Library is an open-source collection of application blocks designed by Microsoft's patterns & practices group. It includes a logging application block that can be used to programmatically record status, warning, or error messages to a variety of log stores - the Windows Event Log, XML files, a database, and so on. log4net is another open-source logging library. It is maintained by the Apache Software Foundation and is a port of log4j, a logging library for Java.
There were no book reviews for this column.
Enjoy! - http://msdn.microsoft.com/en-us/magazine/cc793972.aspx
As always, if you have any suggestions for products or books to review for the Toolbox column, please send them to toolsmm@microsoft.com.
Friday, August 29, 2008
#
I don't know about you, but when it comes to programming I am very particular about whitespace. When updating old code originally written by someone else, the first thing I do is “clean up” the code, injecting whitespace, tabs, and whatnot in the positions that make my anally retentive side happy. I also like my windows in Visual Studio arranged in a certain fashion, although I am not as particular about the VS IDE layout as I am about code whitespace.
Here's the VS window layout I prefer:
- I like Solution Explorer, Properties window, and Server Explorer pinned on the right occupying the same real estate, so that there's three tabs at the bottom right corner of the screen.
- Toolbox pinned on the left (although sometimes I unpin this when working on code).
- Task List, Output, Find Results, and Pending Checkins all unpinned and along the bottom of the IDE.
I really don't like it when two or more windows share real estate on the left, right, or bottom. For example, Visual Studio's default layout is, which has the Solution Explorer on the upper right and Properties window on the bottom right, is annoying to me and is the first thing I fix when using a new install. I also prefer my Toolbox to be arranged alphabetically, not by category.
Are you as particular about your VS layout? How do you arrange your IDE?
Interestingly, I am not a very particular person in other areas of life. In fact, last summer my wife and I went on a 71-day rambling road trip across the country without any set schedule or destinations. Granted, I do like somewhat of a fixed work schedule and get frustrated if there is a break in my planned routine for the day, but I can still function. In short, when it comes to work I like my ducks all lined up in a row, from the way my code is formatted to my daily schedule.
Wednesday, August 27, 2008
#
I recently started reading Fred Brooks, Jr.'s The Mythical Man Month, an influential collection of essays on software project management.
In the introductory essay he has a paragraph that starts with the following words: "Why is programming fun? What delights may its practitioner expect as his reward?" He then goes on to list five reasons, in prose that is poetic:
First is the sheer joy of making things. As the child delights in his mud pie, so the adult enjoys building things... I think this delight must be an image of God's delight in making things, a delight shown in the distinctness and newness of each leaf and each snowflake.
Second is the pleasure of making things that are useful to other people. Deep within, we want others to use our work and to find it helpful. In this respect the programming system is not essentially different from the child's first clay pencil holder "for Daddy's office."
Third is the fascination of fashioning complex puzzle-like objects of interlocking moving parts and watching them work in subtle cycles, playing out the consequences of principles built in from the beginning. The programmed computer has all the fascination of the pinball machine or the jukebox mechanism, carried to the ultimate.
Fourth is the joy of always learning, which springs from the nonrepeating nature of the task. ...
Finally, there is the delight of working in such a tractable medium. The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination.
Of course, we all know that in addition to these joys that make programming fun, there are realities that subtract from the overall enjoyment. Brook addresses these later in the essay by enumerating the woes of programming. The first one dates Brooks's essays, which were written in 1975:
First, one must perform perfectly. ... If one character, one pause of the incantation is not strictly in proper form, the magic doesn't work.
While the programming language syntax rules are strict and literal, today's tools make this a non-issue. If I make a typo writing my code, Visual Studio underlines it with a squiggly. And the cacophony of information on the Internet provides a bounty of code snippets, tutorials, FAQs, and guides that virtually anyone these days can become a magician.
The next two woes Brooks lists are still applicable to today's programmers and are spot on.
Next, other people set one's objectives, provide one's resources, and furnish one's information. One rarely controls the circumstances of his work, or even its goal. ...
The next woe is that designing grand concepts is fun; finding nitty little bugs is just work. With any creative activity come dreary hours of tedious, painstaking labor, and programming is no exception.
The final woe Brooks lists is still applicable today, even more so than it was in 1975:
The last woe, and sometimes the last straw, is that the product over which one has labored so long appears to be obsolete upon (or before) completion.
For me, this is not a woe, as it does not subtract any fun from programming for me. Perhaps it's because I grew up with computers and the rapid and unceasing technology churn. It's second nature for me and most people whose birth date coincided with or came after the birth of the personal computer in the late 70s. But I can see an adult in 1975 would feel overwhelmed by the incessant improvements in technology, each new one rendering the older generation obsolete.
Brooks ends the essay on an upbeat note:
This then is programming, both a tar pit in which many efforts have floundered and a creative activity with joys and woes all its own. For many, the joys far outweigh the woes, and for them the remainder of this book will attempt to lay some boardwalks across the tar.
I'll leave you with some background on Fred Brooks:
Tuesday, August 26, 2008
#
It's amazing how much time speculative development can swallow up during the course of a project. Speculative development happens when a developer implements features above and beyond the requirements based on the assumption that he'll need such functionality at a later point in time. I think it's a trap every developer has fallen into at one point or another. We are tasked with something simple - like exposing the latest news through an RSS feed - and turn it into something complex - like building an entire RSS generation framework that can syndicate any data source.
In The Productive Programmer Neal Ford explains why software projects - as opposed to other engineering projects - are so prone to speculative development:
Usually, in the physical world, things tend toward simplicity unless you add energy to disrupt it. Software is the opposite: because it is so easy to create, it tends toward complexity (in other words, it takes the same physical effort to create both complex and simple software). It can take great effort to pull software back toward simplicity.
In other words, it's expensive in time and cost to increase the complexity of a bridge or car or house, which is why you don't see needless complexity added to such systems. But for software, it may only take a few more hours to add some extra functionality that, while not required now, may be useful down the road. Another factor that leads to a high occurrence of speculative work in software projects is the typical mindset of a programmer. We like order and rigidity and building black boxes that can be plugged in elsewhere and used again. We enjoy challenges and solving problems. Spitting out the latest news in a simple RSS feed is easy, boring even. It's much more mentally stimulating to craft an RSS generation framework. (This predilection of self-directed framework building also helps explain why developers working on existing projects oftentimes advocate pitching the existing code base and rewriting the application from scratch rather than build on top of the work that's already been done.)
The main problem with speculative development is that it adds potentially unneeded code to the project, bloating its size, increasing the surface area of the project, and contributing to the code that must be tested. It's also potentially wasted time. Of course, speculative development isn't a problem if the speculative work is actually needed and used at some future point in time. But because there's no way to definitively say that the speculative work will eventually be needed (or that it will be needed but in some alternate form), it's best to build only what is needed in the here and now.
There's an acronym to keep in mind to help temper speculative development - YAGNI, which stands for "You Ain't Gonna Need It." Ron Jeffries, one of the founders of Extreme Programming methodology, summarizes the idea behind YAGNI succinctly:
Often you will be building some class and you’ll hear yourself saying "We’re going to need...". Resist that impulse, every time. Always implement things when you actually need them, never when you just foresee that you need them. ... You’re thinking about what the class might be, rather than what it must be. You were on a mission when you started building that class. Keep on that mission rather than let yourself be distracted for even a moment. Your time is precious. You might not need it after all. If that happens, the time you spend implementing the method will be wasted; the time everyone else spends reading it will be wasted; the space it takes up will be wasted. ... The best way to implement code quickly is to implement less of it. The best way to have fewer bugs is to implement less code.
Wise words from a wise man.
Monday, August 25, 2008
#
CopySourceAsHtml (CSAH) is a free Visual Studio Add-In created by Colin Coller that turns Visual Studio code - with its indentation, color coding, and line numbers - into corresponding HTML with a few points and clicks of the mouse. This Add-In is great for pasting code samples into blogs and online articles. In fact, I've mentioned CopySourceAsHtml in a previous blog entry.
Unfortunately, the web page that hosts the CSAH Add-In - http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/ - has been offline for over a week now. I've emailed Colin about this outage, asking if it was a temporary or permanent matter, but have not heard back from him. If anyone has a direct line to Colin and can get the inside scoop, I'd be interested in knowing whether the CSAH files have moved elsewhere or if the existing site will be coming back online.
In the meantime, I am posting the Visual Studio 2005 and Visual Studio 2008 versions of CopySourceAsHtml here for others to download.
The Visual Studio 2008 version uses the Visual Studio 2005 version with some additional files created by Guy Burstein. For more on the Visual Studio 2008 version see: CopySourceAsHtml for Visual Studio 2008 RTM. The files available for download above were provided to me by Jason Gaylord. Thanks, Jason!
Monday, August 18, 2008
#
On July 15th I broke my right hand playing basketball, which resulted in a cast that severely limited the mobility and dexterity of my right hand and fingers. Today the cast came off! I am back to having all ten fingers available for typing, writing, eating, dressing, and piano playing! Granted, things aren't back to 100% yet. My wrist and hand muscles are extremely weak right now, but that will strengthen over time. For now I can painlessly use the mouse and type. I get some muscle twinges when playing the piano or gripping small objects (like a pen or pencil). And the doctor said no basketball for at least another month.
After asking for suggestions on how to function at work on a day-to-day basis with one hand, many people chimed in with advice - thank you! Being reduced to typing and programming with one hand is no fun. At first it is extremely limiting and very frustrating. However, over time and with enough practice I was able to significantly increase my words/minute typing speed using my left hand and a lone finger on my right hand. Immediately after my injury I was typing around 30 wpm, but by the time the cast came off I was north of 50 wpm.
The best suggestion I received was to use voice recognition software. I ended up buying a copy of Dragon Naturally Speaking and used it for writing the majority of my emails and articles. It was not very useful when programming, although I did use it every now and then in SQL Server Management Studio to write ad-hoc SQL statements. As my typing speed improved I found myself using Dragon Naturally Speaking less and less. Now that I have full faculty of my right hand I doubt I will use DNS again (unless, heaven forbid, I have another hand injury at some point in the future). While voice dictation is nice, it cannot compete with my typing speed. Also, the error rate on voice dictation is still too high, in my opinion. In my experiences I'd get an error in dictation once or twice per paragraph. While that's not a lot, it does require going back and making the correction from the keyboard most times, and that is time consuming. What's more, I find that when speaking I have to collect my thoughts and decide what, exactly, I'm going to say before speaking it. With typing, however, I just start moving my fingers and the words come to me as I'm clicking and clacking away.
Thanks again to everyone who offered suggestions or shared their stories.
Friday, August 15, 2008
#
Certain features of Microsoft SQL Server 2008 require Visual Studio 2008 SP1. If VS 2008 SP1 is not installed the SQL Server installation will abort with the following error message: "A previous release of Microsoft Visual Studio 2008 is installed on this computer. Upgrade Microsoft Visual Studio 2008 to the SP1 before installing SQL Server 2008."
PROBLEM: You've downloaded and installed Visual Studio 2008 SP1, yet SQL Server 2008 still fails to install with the same error message.
SOLUTION: If you installed a beta version of Visual Studio 2008 SP1 you must first uninstall it and then install the RTM version. You can use the Visual Studio 2008 Service Pack Preparation Tool to effectively remove prerelease versions of the service pack.
If you did not install prerelease versions of the service pack, yet still get this error message, chances are there is a Visual Studio SKU that did not have the service pack applied. For example, if you have both Visual Web Developer 2008 and Visual Studio 2008 Professional on your machine, you need to install both SP1 for the Professional version and SP1 for the Express SKU. In other words, installing the Visual Studio 2008 Professional Server Pack 1 does not apply the Service Pack to Visual Web Developer. Consequently, you cannot install SQL Server 2008 with those features that require VS 2008 SP1 until apply the service pack to the Express SKU. (You can alternatively uninstall Visual Web Developer and then re-download and re-install it, as the current download has SP1 baked into it.)
For more information on installing SQL Server 2008 and the service pack requirements, check out SQL Server 2008, Visual Studio 2008 SP1, and .NET Framework 3.5 SP1 Explained.
For more information on the new features in SP1 pertinent to ASP.NET, see the .NET Framework 3.5 Service Pack 1 Overview.
Thursday, July 31, 2008
#
The final two tutorials (#9 and #10) of my Master Pages Tutorial series are now available on www.asp.net. These tutorials explore two advanced master page scenarios:
- Specifying the Master Page Programmatically [VB | C#] - in most cases a content page's master page is specified statically through the MasterPageFile attribute in the @Page directive. However, it is possible to dynamically set a content page's master page, as this tutorial shows.
- Nested Master Pages [VB | C#] - much like how a content pages can bind to a master page, it is possible for master pages to bind to other master pages. Such nested master pages are quite useful in scenarios where there is an overarching look and feel to a site, but various portions of the site require a more customized and unique template. With nested master pages you can define the global common layout in a top-level master page and then use child master pages to create more specialized layouts for particular sections of the site.
Like my past tutorials, these tutorials are all available in C# and VB versions, include a complete working source code download, and are available to download as PDF, as well.
Enjoy! - http://asp.net/learn/master-pages/
Tuesday, July 29, 2008
#
My Toolbox column in the August 2008 issue of MSDN Magazine is avaiable online. The July issue examines:
- FileHelpers - .NET includes XML serialization capabilities, which makes it easy to load an XML file into a collection of objects and to save object state back out to an XML file. If you need similar functionality for delimited or fixed-length text files (like CSV files), check out FileHelpers, an open-source .NET library created by Marcos Meli that provides such serialization capabilities.
- Blogs of Note - K. Scott Allen - a great blogger with in-depth and timely posts on ASP.NET, LINQ, ASP.NET MVC, and project management.
- YSlow for Firebug - Firebug is a free Firefox extension that is a must-have for all web developers. It captures many important metrics and allows developers to dynamically adjust the page's markup, CSS rules, and to debug JavaScript, all from the browser! YSlow for Firebug is an add-on to Firebug that provides a bevy of performance metrics and targeted guidelines on how to improve a page's response time.
For The Bookshelf section I reviewed Accelerated VB 2008, by Guy Fouche and Trey Nash. An excerpt from the review follows:
As a freelance developer and consultant, I work with clients who have existing apps but need help in adding new features. Some applications are written in C#, others in Visual Basic, so I need to have a mastery of both languages. Visual Basic is easy to pick up; its prose-like syntax and straightforward semantics have helped make it one of the most popular programming languages in the world. But there's a wide gulf between knowing Visual Basic and mastering it. To help bolster my Visual Basic skills, I picked up Accelerated VB 2008 (Apress, 2008) by Guy Fouché and Trey Nash. This book dispenses with the typical page-filling content found in most computer trade books and replaces it with distilled information and code examples that get right to the point. Because of this terse style, however, Accelerated VB 2008 is not for beginners who are interested in learning Visual Basic, but it's ideal for intermediate developers who are either looking to bolster their understanding of Visual Basic or who are in need of a good desk reference.
Enjoy! - http://msdn.microsoft.com/en-us/magazine/cc721607.aspx
As always, if you have any suggestions for products or books to review for the Toolbox column, please send them to toolsmm@microsoft.com.
Saturday, July 26, 2008
#
I've been using Microsoft Virtual PC product for many years, posting separate VPCs for each client's work and for test beds for installing beta software or trying out products for my Toolbox column. A couple of months ago I started noticing that when in a VPC the Tab and Esc keys were being ignored. For example, when I would use Alt+Tab from within a VPC I would be toggling through the applications in the host environment. Likewise, if I hit Ctrl+Esc from within a VPC it would display the Start menu options in the host environment. Because I try to use the mouse as infrequently as possible and stick to keyboard shortcuts, having a nonfunctional Tab key seriously hindered by productivity. From Alt+Tab to moving from one form field to the next to inventing code, it's amazing how frequently I use the Tab key.
My initial assumption was that there was some problem with Virtual PC. I found information noting such problems when using UK keyboards, but nothing specific to my problem. My research revealed that a general rule of thumb was to check for programs in the host environment that might be capturing keystrokes and thereby "stealing" the keystrokes from the VPC. My approach was rather ham-fisted, but what I did was the following: I launched task manager and started killing off processes one at a time. After each process was killed, I would go over to the VPC and see if it now recognized the Tab and Esc keys.
The culprit ended up being FogCreekCopilotHelper.exe. Copilot is a desktop sharing tool from Fog Creek Software that I use now and then when providing telephone-based consulting services. This process is supposed to shut down automatically when the Copilot software closes. However, sometimes it does not cleanly die off; instead, it lingers around and seems to swallow up the Tab and Esc keys in Virtual PC.
I first detected that FogCreekCopilotHelper.exe was the source of my problems several weeks ago, but I held off posting a blog entry because I wanted to observe how exactly this problem arose. I've had several sessions with Copilot where the FogCreekCopilotHelper.exe process shutdown cleanly and did not interfere with my Virtual PC experience. In the times when it has caused trouble I noticed that mid-way during the Copilot session the Tab and Esc keys stopped working in Copilot! The same behavior I noted in Virtual PC after the fact. And, sure enough, when Copilot loses the Tab and Esc keys the FogCreekCopilotHelper.exe process does not cleanly die, but rather sticks around and steals the Tab and Esc keys from Virtual PC.
Long story short, if you lose functionality for certain keys in Virtual PC first look for the FogCreekCopilotHelper.exe process and kill it if it's floating around. If you do not use Copilot (or if this process is not present) then start to systematically kill off processes until you find the troublemaker. This approach of methodically killing processes is not very elegant, but can help detect the problem assuming you do not inadvertently kill essential processes during the genocide.
Friday, July 25, 2008
#
In my last blog entry, The CreateUserWizard and Validation ErrorMessages, reader Andrei Rinea commented:
I wish the whole Membership set of controls would be replaced with better ones. Very often I need to have an authentication/authorization mechanism that doesn't need a username but an e-mail. I need email verification and in case the user loses the password he/she should be able to recover it without knowing (a) username.
This scenario is possible, but requires some customizations of the Membership controls. For instance, you can configure Membership so that an Email is not required, and then customize the CreateUserWizard control so that it uses the text “E-mail:” in place of “Username:” (thereby storing the user's e-mail address as their username.
The CreateUserWizard control can also be customized to require that user's verify their email address before being able to log in. See these two articles for more information and to download a complete, working example:
Personally, I quite like the existing Membership controls. They provide a suitable out-of-the-box implementation that allows one to get started without having to write a lick of code, yet are highly customizable through properties, templates, and events, allowing for virtually unlimited scearios and workflows. And if a particular control doesn't cut the mustard you can always create your own UI that uses the Membership framework behind the scenes (via the Membership class).