Book Review #11: The Bug, by Ellen Ullman

The Bug by Ellen UllmanWritten in both a narrative and story-like style, The Bug centers on the story of a software glitch, a defective feature, a non-desired behavior of a computer program, commonly known to us (software developers) as a bug. A bug which a novice tester found and reported to the software engineer in charge of the most complicated layer of a software: the UI layer. The year? We’re talking 1984, baby! This was before windows, icons, menus and pointers were mainstream in UI-driven applications! But this bug was not like any other bugs. It’s one of those bugs that shows up when you least expect it: in a demo in front of potential customers, at a sales meeting, etc. It’s one of those bugs that are super hard to reproduce manually. Sometimes it shows itself plainly and other times, even though the same repetitive actions are executed (or so we think), it stays hidden. It’s one of those bugs that doesn’t let you sleep comfortably at night. It’s one of those bugs that makes you skip supper with your loved ones. It’s one of those bugs that causes you to question yourself, “Am I made for this? Am I as smart as I thought I was? Am I competent? Do I know what I’m doing exactly?”. It’s one of those bugs that can make your world dark, lonely, aggressive, egoist, godless. You know what I’m talking about? The bug. THE bug.

Sooner or later, a professional software developer will encounter one of these, and will have to deal with it. Not only the technical aspects surrounding the bug, but also all the human interactions involved in finding the cause and the solution for it. In this story, we get acquainted with Ethan Levin, the software engineer responsible of the UI layer for a database application at software company. Throughout the book, we are invited to see how his life will change to chaos as the lifespan of this bug goes from days to months. A bug which he was assigned to fix. A bug which he doesn’t know how to fix because of several reasons very well explained by the author, Ellen Ullman. The story also introduces us to Roberta Walton, a novice tester who first made acquaintance with the bug. Not very much interested in the technicalities of programming (compilers, languages, operating systems, device drivers, etc.), she is somewhat obliged to learn and get familiar with them because without those tools and knowledge, the bug will get her too. Together, they will try to hunt and kill the bug.

What I found interesting about the story, is how familiar a computer bug can be. For example, a bug could have such a personality and character that it reminds us of someone. Sometimes it can resemble ourselves. That’s when it gets scary! I had a lot of trouble putting the book down. I read it when I was doing my physio exercises, on the way to church, while my wife was shopping at Wal-Mart, etc. Whenever I had free time, I would dive right into it. The story reads itself so well that I could easily imagine the scenarios, the faces and the emotions each character was going through.

In one instance, after having found the solution to get rid of the bug, Roberta reflects on how much trust we put into other software-driven appliances (machines, Web applications, vehicles, etc.) that surround our lives :

“Which led me to the question: Was it still a bug? If a flaw is there and you don’t see it, is it still a software error? Or is it more like a defective gene, waiting for an environmental trigger to come along and kill you? […] This latent, dormant, sleeping bug could then awake, and everything – a program thought to be working – would suddenly crash. I think about this every time I get on a plane, or make an electronic payment, or get an X ray, or step into an elevator. Code, all around me. Working, as far as anyone can tell. Somewhere in there – hiding, biding its times, only waiting for a software patch, or a device-driver update, or a network installation, or a well-intentioned programmer to come along and tweak the code – is a bug […] ready to bring the system down.

What’s funny about this observation is that I ask myself the same thing whenever I step into a plane, a car or an elevator! Just the thought about it makes me think that one day we might read in the front page of a newspaper the following headline: “He died because of a bug. A glitch.” A person born from a mother, nourished and well educated, died (if not to say ‘murdered’) by a couple of misbehaving ones and zeroes. What a thought!

I highly recommend this book to CS and SWE students that would like to get a taste of what the industry is like. What kind of human and professional behaviors to avoid, and which ones to adopt, because there is SO much more to software development than code. I also recommend it to software developers, testers, consultants, managers and teachers too. It’s superbly well-written! A great entertainment for the geek in us.

P.S. There is actually a small bug in the book. Look at page 176. Can you guess what it is?

Customizing your command prompt

Yesterday, I was playing around with customizing my command prompt. I wanted to rapidly know in which directory I was in at all times. At the same time, I wanted to display the date and time, so that whenever I had to do some comparison with a file’s timestamp, I would could know the current date and time from within the same window. Basically, I wanted something like this:

[$CURRENT_DIRECTORY$]
$DATE$ $TIME$ >

While searching around the Web to get an idea how to do this, I landed on this page which does a great job explaining how to do exactly this. I’ll resume the steps here, but feel free to visit that site for even more information on this matter:

  1. Launch a Command Prompt which will be used a sandbox to try out your new prompt.
  2. Use the table below as a reference to the symbols you can use to define your new prompt.
  3. Type prompt followed by the symbols as they appear and press <Enter>.


Symbol

Value

$$

$

$_

(Causes a CR/LF; new line)

$A

& (ampersand)

$B

| (pipe)

$C

(

$D

Current date

$E

Escape code

$F

)

$G

>

$H

Erases the previous character

$L

<

$N

Current drive

$P

Current drive and path

$Q

=

$S

(space)

$T

Current time (HH:MM:SS.mm)

$V

Windows version number

[%computer_name%]

Your computer name in between brackets

%environment_variable%

Displays the value of the environment variable

 

For example, if I wanted to display only the current date followed by a greater-than symbol, I would type: prompt $D$G and press <Enter> (don’t close that window yet!):

image

At this point, you can view what prompt will be used. Unfortunately, this will not stay as the default prompt. If you close the window, you’ll see again the default prompt which is $P$G (show the current path, followed by the greater-than sign).

To permanently make the changes for all instances of the command prompt window, you will have to play in the registry. Trust me, this one is pretty easy:

  1. Fire up the registry editor (START, RUN, type regedit then press <ENTER>)
  2. Navigate to the following node: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
  3. If it doesn’t already exist, create a new string value named Prompt
  4. Assign your custom prompt as the data value to it (see the following screenshot for an example) and press OK.
  5. At this point, you should restart your computer to affect the changes permanently.

image

Next time you’ll launch a command prompt window, it’ll show your custom prompt.

Mapping a domain name to an IP address in the HOSTS file to bypass a DNS resolver.

When I made the switch to another hosting company, I had to point my domain name (briandicroce.com) to their DNS servers. After that, I couldn’t access my site from the domain because the DNS servers associated with my ISP had the previous DNS settings of my domain name in its cache.

My first though to verify that everything was working fine with the new DNS settings was to visit my site from another computer hooked up with another ISP. So I launched a remote desktop session with my PC at work, and from there I could clearly see that my site was accessible and running well.

I pinged my domain name from that PC and received an IP different from the one I got when pinging the same domain name from my own PC hooked up with my ISP. So which IP was the right one then? I visited Network-Tools.com to get this answer. Bingo! My ISP’s DNS server was pointing my domain name to the previous (old) IP addresses. I called the technical support, but they told me that they cannot flush the cache of the DNS server for one site.

So I tried a couple of different things on my end:

  • I tried to release and renew my network adapters with these commands: ipconfig /release and ipconfig /renew.
  • I tried to flush my local DNS resolver cache: ipconfig /flushdns.

Nothing! Every time I would visit my site, I would still receive an error somewhat to a “Could not locate remote server” (I’m an Opera fan). Even after doing a tracert briandicroce.com, I could see that the route would break after a couple of hops.

Anyhow, I managed to fix my problem by modifying the local HOSTS file (see link to find the location of this file in your computer) and manually mapping my domain names (blog.briandicroce.com and briandicroce.com) to the IP addresses of my new hosting servers. Here are the steps to follow in case you’re having the same problem I did (Windows machine only):

  1. Edit the HOSTS file (no extension) with a text editor using Administrator privileges. The location of this file is in %SystemRoot%\system32\drivers\etc\ by default. Note that users of 64-bit versions of Windows Server 2003/2008, and Vista (Windows 7 excluded) cannot access the HOSTS file with a 32-bit editor.
  2. Enter the mappings of your domain names to their corresponding IP addresses. The first value should be the IP address that the domain name (second value) should point at. Make sure to separate the IP Address from the domain name with a whitespace.
  3. Save the file.

And that’s it. Now when you access your domain name, Windows will check to see if there’s an entry for it in the HOSTS file and will use its corresponding IP address, therefore bypassing your ISP’s DNS server’s resolver to direct to the site.

After a couple of days/weeks/months, you could probably remove those entries in the HOSTS file in the case that the DNS server actually flushed its cache.

Another jewel from Sysinternals: Desktops, a multiple virtual desktops manager

I love Windows 7. It makes me enjoy my ThinkPad T61 even more! It’s fast. It’s not too greedy for RAM. And it’s fast! Super fast!

Sure, there are some extra things I wish it had, such as the possibilities to extend the taskbar on external monitors and to pin windows on top of other windows, etc., but I understand that we can’t have it all…all the time. I’m a software developer too, so I get it.

Anyhow, as I was looking around for a good “multiple virtual desktops” application that I could use to load applications in various desktops, I managed to find a little jewel : Windows Sysinternals Desktops. If you know about Windows Sysinternals, then you know that those guys don’t release crap. This little app is great because it’s small and it works! No hassles! Here’s a small description of it that I’ve taken from their website:

Unlike other virtual desktop utilities that implement their desktops by showing the windows that are active on a desktop and hiding the rest, Sysinternals Desktops uses a Windows desktop object for each desktop. Application windows are bound to a desktop object when they are created, so Windows maintains the connection between windows and desktops and knows which ones to show when you switch a desktop. That making Sysinternals Desktops very lightweight and free from bugs that the other approach is prone to where their view of active windows becomes inconsistent with the visible windows.

imageI kept the hotkeys by default, so that Desktop 1 is mapped to ALT+1, Desktop 2 is mapped to ALT+2, etc. That way, I can have Outlook and Opera sitting quietly on Desktop 1, Visual Studio on Desktop 2, a virtual machine on Desktop 3, and Word/Excel on Desktop 4. That’s right, you only get four virtual desktops with this little nifty tool (why would anyone need more than four?). And it works great with multiple monitors too!

What I like about it, is that each virtual desktop manages its own taskbar, system tray, and applications. Which means that when an application is loaded, it is running in its own desktop. Suppose you loaded Visual Studio on Desktop 3, but you’re currently working on Desktop 1. If you shutdown Windows, it will say that some apps are still running and you might not know why or where…the best guess is that it is running in one of the other desktops.

One little caveat of using this tool is that my favorite Windows application launcher, Launchy, will only work on Desktop 1. So, I’m kinda screwed if I’m in Desktop 2, 3 or 4 and trigger Launchy…because it won’t work! But like I have previously said, I’m a software developer too, so I get it that I can’t get it all…all the time. If you know how to make Launchy works on all virtual desktops, please tell me how you did it. It will be very much appreciated.

If you’re looking for a fast, free, small (62kb), simple virtual desktops manager that runs once downloaded (there’s no useless installer with this one!), look no more! Windows Sysinternals Desktops is the tool you need. I love it!

Migrating a Wordpress site from BlueHost to WebHost4Life

This week, I migrated my blog which was hosted by BlueHost to WebHost4Life. I highly recommend BlueHost if you’re looking for a LAMP-based (Linux+Apache+MySQL+PHP) hosting package. Their pricing is fair, the quality of service is excellent and the technical support is unbelievable. The reason I made the switch was that I’m working more with ASP.NET MVC and I wanted a provider which supported .NET 3.5 so that I can publish some of my projects in the public domain. After reading some reviews online, I opted for WebHost4Life.

The transition of my blog, which is powered by Wordpress, didn’t go as smoothly as I hoped. While at BlueHost, the blog was being hosted in a LAMP environment. At WebHost4Life, the blog was going to be hosted in a Windows/IIS/ASP.NET environment. I thought it was just a matter of transferring some files from servers and importing a backed-up database script. Nope.

Here are the steps I followed to successfully transfer my Wordpress blog from a LAMP environment  to a Windows/IIS/ASP.NET environment. Or more specifically, how to transfer your Wordpress blog from BlueHost to WebHost4Life:

NOTE: Make sure you have properly configured DNS settings for the domain name that points to your blog or site.

On the BlueHost (or LAMP environment) side :

  1. Upgrade your current Wordpress to the latest version available.
  2. Make sure your plugins work with the latest upgrade. If they don’t, either upgrade or delete them.
  3. Deactivate all your plugins to avoid any problems when migrating your current database.
  4. Backup your current Wordpress database. This should generate a SQL file which will be used to restore the database in another instance of MySQL.
  5. Make a local copy of your Wordpress/blog directory for backup purposes. You’d normally do this with an FTP client. If you don’t have any FTP client, I highly recommend you use FileZilla.

On the WebHost4Life (or Windows/IIS/ASP.NET environment) side :

  1. Install whatever version of Wordpress available through their automated script installer. You want to do this because the automated installer will create the database for you, configure the correct values for the database server name and other settings which you don’t have to enter manually. If you aren’t lucky enough to have an automated script installer provided by your hosting company, simply install the latest version of Wordpress directly in the server (don’t forget to create the database for your Wordpress blog).
  2. Import/restore the backed up database script that was generated in step 4 of the previous section.
  3. Copy all the content of the Wordpress directory that you backed up in step 5 of the previous section in your server. WARNING : Make sure not to overwrite the wp-config.php file in the root of your Wordpress installation directory.
  4. Fire a browser and go in the admin page (\wp-admin) and log in to make sure everything is fine.
  5. Activate any plugins that you have deactivated in the previous section.
  6. If you’re using “pretty” permalinks for linking to your posts, they might no longer work because IIS 6.0 does not support mod_rewrite (read this to know more about this and why it doesn’t work anymore). In short, “pretty” permalinks result in HTTP 404 errors which is actually a false negative since it should work. The solution to make this work is to create a PHP file which provides a URL mod-rewrite workaround for IIS 6.0 and Wordpress (works with v2.8+). Read the following article to know how to do this (trust me, it’s very simple). I named that file ‘404-handler.php’ as was suggested in that article. Upload the file somewhere in your Wordpress directory (I just put it in the root installation directory).
  7. Now you should configure the custom error pages handled by IIS so that when a request generates an HTTP 404 error, IIS will redirect to that ‘404-handler.php’ created in the previous page which will take care of the magic. So to this:
    1. Log in your WebHost4Life control panel.
    2. Click on the “Site Admin” tab.
    3. Under the “IIS Manager” section, click on “Set Custom Error”.
    4. Click on the “Go” link associated with the domain name for your blog.
    5. For the error associated with 404, click on the “Edit” link.
    6. Specify the location of the ‘404-handler.php’ file (relative path).
    7. That’s it! Your “pretty” permalinks should now work!
  8. Now you must set the proper security permissions to your Wordpress directory structure so that you can edit files from the dashboard. To do this, follow these steps:
    1. Log in your WebHost4Life control panel.
    2. Click on the “Security” tab.
    3. Under the “Site Access” section, click on “File Permission”.
    4. Locate your Wordpress folder then click on the “Edit” link associated with it.
    5. In the drop down list, select the NETWORK user and give it the following rights: READ, WRITE, EXECUTE and DELETE.
    6. Make sure to tick the checkbox next to “Propagate changes to sub directories and files”.
    7. Click on “Make Changes” (ONCE!!!) and be patient.
  9. You will also need to activate/configure the “Cimy Swift SMTP” plugin which comes with the installation to send email notifications from within your Wordpress site. It’s really not that hard. Read this article to know how to configure the plugin.
  10. That’s it! You’ve made it! See if everything works correctly…or post your question if it didn’t. I’ll try my best to help you out.

Best of luck!

Why you should use static read-only fields over constants when dealing with strings

It’s really wonderful when you learn something new once in a while. As I was discussing with another .NET developer about the importance of knowing when to use constants and fields, he corrected me when I mistakenly told him that String.Empty was implemented as a constant.  In fact, if you look inside the String class, you’ll actually see that String.Empty is not implemented as a constant, but as a field (a static read-only field to be precise).

As I was thinking about the reason behind this, something hit me: I should be conscious of my decision whether I should use a constant or a field when dealing with strings.  The reason is simple: avoid unnecessary performance hits.  Take note that the only valid reference type for a constant is either string or null because you cannot instantiate a reference type in compile-time, which is when constants are evaluated.

I made a simple test to verify my little theory, since I couldn’t find a good answer for it on the Web. The test consist of a class that declares both a constant string and a static read-only string field. In its entry method, I call various methods which iterate a certain number of times (10, 100, 1000, 10 000 and 100 000) and use either the constant or the static read-only field respectively.  Here’s a sample code I used for this test:

class Program
{
  private const string Constant = "Constant";
  private static readonly string field = "field";

  private static void Main(string[] args)
  {
    // 10 iterations
    DoConstant10();
    DoField10();

    // 100 iterations
    DoConstant100();
    DoField100();

    // 1000 iterations
    DoConstant1000();
    DoField1000();

    // 10000 iterations
    DoConstant10000();
    DoField10000();

    // 100000 iterations
    DoConstant100000();
    DoField100000();
  }

  private static void DoField100000()
  {
    string s = string.Empty;
    for (int i = 0; i < 100000; i++)
	  s += field;
  }

  private static void DoConstant100000()
  {
    string s = string.Empty;
    for (int i = 0; i < 100000; i++)
	  s += Constant;
  }

  // And so on...
}

Next, I profiled the application with JetBrains DotTrace 3.1 (using the standard configuration options) and got the following results:

image

We clearly see that for the same iterations, using a string as field rather than a constant has almost a 2:1 performance improvement ratio over the latter.  Now, the title of the post is “Why you should use…” and not “Why you must use…” because there are some scenarios when using a string constant is better suited, such as when the constant is being used as a case in a switch statement (you cannot use a static readonly field as a case in a switch statement because its value will not be known until runtime).

Another thing you should be conscious of is relying on your experience rather than a tool’s recommendation. For example, when you declare a static read-only string variable, ReSharper will recommend you to transform it as a constant.  You shouldn’t always obey the tool unless you know exactly the tradeoffs and have considered the impact and risks associated with the decision.

image Be a good judge over your codebase. Analyze the evidence and study the tradeoffs. There’s nothing like a good profiler to uncover the truths behind your code.

Copy files from build events within Visual Studio without Windows UAC problems

In my projects, I often have to copy some files in either a pre-build or post-build event within Visual Studio.  Since installing Windows 7, it seems that the copy command from those build events generates an error with a not very helpful message such as the following one:

imageThe “..exited with code 1” leaves me dreaming about a ton of causes for this error. When manually copying the file to the destination directory (as copying AmazonBookLinker.dll to C:\Program Files\Windows Live\Writer\Plugins\) via Windows Explorer, I get the following second strike:

imageAt this point, I’m playing around with security permissions for both files and destination directory without any positive result.  The solution I came about this problem is to actually run Visual Studio with administrator privileges by right-clicking your Visual Studio file icon, and selecting “Run as administrator”. If you want to make this a permanent solution:

  1. Open the properties window for Visual Studio
  2. Go to the Compatibility tab
  3. Under the “Privilege Level” box, check the “Run this program as an administrator
  4. Click on OK
  5. [Optionally] Click on the “Change settings for all users” button apply this privilege to all users on the machine.

image

Installing NVIDIA drivers on Windows 7

I’ve recently installed the latest operating system from the good minds at Redmond, Windows 7 Ultimate, on my Lenovo Thinkpad T61.  The only problem that showed up after the installation (which I should add was the fastest and easiest installation of Windows so far) was that my video card’s drivers, a NVidia 140m card, wouldn’t install successfully from NVIDIA’s Windows 7 drivers download page.  This meant that I couldn’t support neither the native resolution (1680×1050), nor dual monitors on the dock station.

As a matter of fact, I would get the following error message when launching the drivers setup file (186.03_notebook_win7_32bit_international_whql.exe).

image

Therefore, I had to get my little act together and manually install the drivers.  The following instructions should help you install your NVIDIA’s video card drivers on Windows 7 if the setup file won’t do it for you…for some reason.

  1. Go to NVIDIA’s Windows 7 drivers download page and download the drivers specific to your video card.
  2. Run the downloaded executable which should extract the files in a directory (by default C:\NVIDIA\DisplayDriver\###\International, where ### corresponds to the version of the setup file.  Mine was 186.03, therefore the directory was C:\NVIDIA\DisplayDriver\186.03\International).
  3. Browse to that directory (C:\NVIDIA\DisplayDriver\###\International) and in the Display folder, open the ListDevices.txt file with your favorite text editor.
  4. At this time, you’re looking for the specific INF file which holds the drivers information for your card. This step should be easy if you know the model of your video card (check your PC manufacturer’s website if you have no clue what is the model of your video card). For example, my video card is a NVIDIA Quadro NVS 140M. Therefore, I would either search for “NVIDIA Quadro NVS 140M” precisely or simply “140M”.  The search result tells me that the INF file I should be interested in is NVDM.INF (the one in a red square in the following screenshot).

image

  1. Now that we know which file holds the drivers information, we should locate it without problem. In my case its path is C:\NVIDIA\DisplayDriver\186.03\International\Display\NVDM.INF.
  2. Now open your display settings (Control Panel\All Control Panel Items\Display\Screen Resolution) and click on the “Advanced settings” link.

image

  1. On the Advanced Settings window, click on the Adapter tab, then on the Properties button.
  2. From the adapter properties window, click on the Driver tab, then on the Update Driver… button.
  3. On the “How do you want to search for updated driver software?” window, click on the “Browse my computer for driver software” button.
  4. On the “Browse for driver software on your computer” window, click on the “Let me pick from a list of device drivers on my computer” button.
  5. On the “Select the device driver you want to install for this hardware” window, click on the Have Disk… button.
  6. On the “Copy manufacturer’s files from:” text box, simply specify the INF file path from step 5 or simply browse for it, and press the OK button when done with this step.
  7. Now simply select your NVIDIA video card model from the list and click on the Next button (click on YES if you get a warning from updating the driver). Windows 7 should now be installing the drivers for your video card.
  8. Restart your computer to apply the new video settings.

I hope this post helped you to install your NVIDIA video card drivers on Windows 7. Feel free to post you question or comments.

Quick access to useful documents inside Visual Studio

Here’s one of those little tips that can save you time and useless brain processing when the need arises.  When developing in Visual Studio, does it ever happen that you need to read some documentation pertaining to your current work?  In my case it happens a lot.  I don’t like to switch context and fire up a web browser to find the needed documentation, or even launch Windows Explorer to find that document in some obscure, deep directory hierarchy.  No, instead I like to have everything I need, whether tools or documentations, under my fingers in one place: inside Visual Studio. 

Two documentations that I use the most when programming in .NET are the ReSharper 4.5 Default Keymaps and the C# Language Specification (ECMA-334).  In order to quickly access those two documents (and future documents I might need), I simply created an entry in the External Tools section of Visual Studio.  In order to do this, you can follow these simple steps:

  1. Go to Tools -> External Tools…
  2. In the External Tools window, click on the Add button to create a new entry
  3. Fill in the required information, such as Title, Command, Arguments, etc.  In my case, the Command is simply the path to the executable of my favorite PDF reader (Foxit Reader) and the Arguments is simply the path to the PDF file.  You can also define a keyboard shortcut for them by prefixing the “&” symbol to one of the letters that aren’t already defined as shortcuts. 
  4. When you’re done, click on OK

Take a look at the following screenshot:

With this little setup, I don’t need to go to either the ReSharper or ECMA’s website, not even launch Windows Explorer to look for those files.  I have access to those files directly from Visual Studio.  No more context switching.

Three talks you should watch this week (Series #1)

Whenever I can’t get myself too tired to go to sleep, or I’m on the bus commuting to work or to a client, or plain simply have an hour or two open in my schedule, I often fill it up watching a few talks online.  Though I’m passionate about software development and technology in general, I don’t always focus entirely on it, as it isn’t very fulfilling for the imaginative mind.  Recently, I’ve listened to some great talks about technologists speaking about starting online businesses, marketing, life, faith, etc., which really pump me up to a level that makes me thankful to live, to dream and to achieve what I value most in life.  I’ll start making a series out of this one, as I believe it can be as helpful and motivating to you, as it is for me.  That being said, here are the first three talks I recommend you to watch this week:

  1. David Heinemeier Hansson on The Secret To Making Money Online (less than 30 minutes)

In this talk given in 2008, David Heinemeier, the creator of the Ruby on Rails framework and partner at 37Signals, gives a very creative and down-to-earth talk on how to create a profitable startup company.

  1. Guy Kawasaki on The Art of Innovation (less than 60 minutes)

This is the first time I heard Guy Kawasaki speak.  This guy is a one of my “online heroes”.  He’s smart, he’s funny, and he speaks from experience.  In this talk, Guy talks about innovation about products, services and marketing.  He shares his experience from his work at Apple to now as a venture capitalist.  You’ll also learn about the 10-20-30 rule that can increase your chances in not only getting fund for your business, but most importantly, getting your point across.

  1. Joel Spolsky on What Makes a Great Software (less than 60 minutes)

This is a talk that Joel Spolsky, founder of Fogcreek Software, gave as a keynote at RailsConf 2008, where he shares his valuable insight in what really makes a great software, so much so that we can actually qualify the software as great.  His talk is fantastic: it’s entertaining, it’s focused and it’s without a doubt an eye-opener for software developers to watch out some common pitfalls that can make your software not being adopted at all by potential users.

The Architectural Journal, a quarterly journal about software architecture

image Microsoft has many valuable resources for .NET developers under its MSDN umbrella: newsgroups, blogs, forums, magazines, etc.  One very valuable resource from Microsoft that seems to be ignored by most developers is The Architectural Journal:

The Architectural Journal is an independent platform for free thinkers and practitioners of IT architecture.  New editions are issued quarterly with articles designed to offer perspective, share knowledge, and help you learn the discipline and pursue the art of IT architecture.  The Architectural Journal reaches over 67,00 subscribers worldwide.

I think one reason that it isn’t getting much attention is because its “feedless”, meaning you can’t directly subscribe to a feed, through your browser, that will notify you whenever a new issue has been published.  So in order to get notified when a new issue has been published, you need to subscribe through a fairly simple, but tedious, subscription workflow.  Once subscribed, you’ll get the quarterly journal as a PDF as soon as it’s released.  In short, here are the steps you should follow in order to subscribe to The Architectural Journal:

Go to the e-newsletters page in the Profile Center.  You may be required to sign up for a Windows Live ID account if you don’t have one already.  You may use your current email account or create a new one if you don’t have one.  From there, you follow these three steps:

  1. Find The Architectural Journal in the list of available communications on the left and select it.
  2. Press the Subscribe button.  You should now see your choices in the list on the right.
  3. Select your delivery format: HTML (suggested) or plain text.

(Note: it would’ve been much easier had someone put an RSS feed link instead.)

So that’s it! Now, you should be getting four issues per year.  All great content about software architecture topics.  All free.  Past topics include:

You can also skip the whole subscription process and directly download the current and previous issues in English, French, Spanish, etc., as a compressed (ZIP) file.

My five favorite features in ReSharper 4.5

With the recent release of ReSharper 4.5, many productive features have been added to this already great product, such as performance and memory usage improvements, solution-wide code inspections, VB9 support, and many more.  I’ve been using ReSharper as my pair programmer for many years as it helps me to enhance my C# refactoring whenever I overlook some portions of code I’m writing, as well as to manage my unit tests.  In this post, I will concentrate on sharing with you my five most favorite new features in ReSharper 4.5.

1. Find dependent or referenced code

Using this new feature, you can find dependent or referenced code at either a project or file level.  Before going forward with this feature, it is important to understand what is meant by “dependent code” and “referenced code”.  Both of these terms have to do with dependencies/coupling.  When you ask ReSharper to tell you the dependent code at the project level, you are actually asking it to tell you which other projects (or assemblies) are dependent on that specific project.  On the other hand, when you ask ReSharper to tell you the referenced code at the project level, you are asking it to tell you which other projects (or assemblies) that specific project depends on.  For example, suppose the following UML class diagram:

In this scenario, I have four different assemblies: one client console executable (Client), and three class libraries (Provider, Utilities and SecurityManager).  Our Client executable references the three other assemblies because it’ll make use of their services.  Those references were created when I asked Visual Studio to add me the references for those three projects at the project level.  Now, if I were to ask ReSharper to tell me the dependent code at the project level (which means that you right-click on the Client project in the Solution Explorer, and then click on the Find Dependent Code contextual menu item), a message box will appear telling me that “Code dependent on project ‘Client.csproj’ was not found”: 

This is normal, because according to our class diagram above, Client has an afferent coupling of zero (Ca = 0). 

Afferent coupling(s) is the number of class(es) outside this component (i.e., Client) that depend on classes within this component (i.e., Client). 

On the other hand, if we were to ask ReSharper to tell us the referenced code at the project level (for Client), by this time clicking on the Find Referenced Code contextual menu item, you will get the following results:

In this case, ReSharper is telling us the types which are being used in that specific project (Client), even .NET types and assemblies like mscorlib.dll.  Since the Client class has a positive non-zero efferent coupling (Ce > 0), we actually get a result.

Efferent coupling(s) is the number of classes inside this component (i.e., Client) that depend on classes outside this component (i.e., Client).

These results could look daunting at first sight, but that’s because the results window is showing too much information.  All you have to do to get a more simplistic and lighter view of the results is simply to click on the Filter Usages button (that’s the one surrounded in red in the screenshot below) and unselect the Show Attribute Usage from the proposed choices, as you don’t really care that you’re depending on the AssemblyAttribute class for example.  Furthermore, you should also click on the Merge Occurences on the Same Line button (that’s the one surrounded in green in the screenshot below), so that you eliminate some of the redundancy usages on the same line.  Finally, choose an appropriate view to group your results (in this case, I have chosen to group the results by Namespaces and Types.  That’s the one surrounded in blue in the screenshot below).  This will give you the following (much more compact) result view:

NOTE: If you only reference external projects or assemblies in a project without actually using the public types or members in those external dependencies, ReSharper will not tell you that you are actually referencing those dependencies.  This is pretty slick, as you can visually know whether or not a reference is unnecessary, and thus proceed with its removal.

Ah, much better! And you know what?  That’s pretty much right, because the Client class is actually using those classes (Provider, SecurityManager and Utilities), as shown in the screenshot below:

At the file level, you only get to ask ReSharer to tell you the referenced code, through the Find Referenced Code contextual menu item.  In this case, the results will include any type being used in that file.  Suppose for example that in the SecurityManager class, you’re using an instance of a Logging class to log some errors in a few critical methods.  In that case, the results will include the Logging class, as it is a type being referenced in that file.  So far, so smart.

2. Go to implementation (Ctrl+Shift+Alt+B)

This one is pretty simple and very much useful.  Suppose you have the following class hierarchy:

image

In the previous versions of ReSharper, you couldn’t ask the tool to directly tell you which concrete classes derived from an abstract type.  Instead, you had to select the abstract type and ask it to tell you the derived types (or inheritors) through the Ctrl+Alt+B shortcut, which would give you a list of all the types deriving from that abstract type…even if those derived types were abstract themselves.  This was pretty frustrating when you had a hierarchy with a lot of abstract relationships amongst types, as it was the case in one WCF-driven project I was involved in, because you would lose a couple of seconds filtering out the concrete types from the abstract ones in the results list.  Well, that’s an old story because now you can get the list of all the concrete types (or implementation types) directly from a new shortcut: Ctrl+Shift+Alt+B, or through the “Go to implementation” command in the “Go to” navigation menu.  For example, if you asked ReSharper to tell you the concrete classes for IProvider, it’ll tell you that MembershipProvider and SecurityProvider are the only ones.  It will ignore ProviderBase, as it is abstract.  Well done!

3. Naming styles

With ReSharper 4.5, we get more flexibility in the naming style department.  You can apply either a common naming style for both C# and VB code, or set one differently for each of them.  It’s up to you.  The UI interface to manage the naming styles is pretty simple.  Here, for example, is the Naming Style window pertaining to both C# and VB:

So you get a list of predefined styles out-of-the-box which might suit most of your basic needs.  The flexibility offered by these features comes in handy when you want to create new styles, modify some existing ones, etc.  Suppose you want to add a new naming style for private fields only, and make them prefixed by an underscore.  You would simply click on the “Add” button under the User defined naming rules panel, which will show the following window:

 

All I have to do is select the affected entities, which in this case would be “Field” and “Readonly field”.  Then I would specify the access modifiers, which sould be Private and Protected. Following that, I will specify the underscore as the name prefix and tick the lowerCamelCase naming style, as to be follow the .NET design guidelines.  Finally, I would set the rule description to something explicit, such as “Private fields”.  That’s it!  Now I can save and share the code style file with my team.

4. Collapse all project nodes (in Solution Explorer)

Suppose you have the following project structure in Solution Explorer:

This would be a very typical folder structure in an ASP.NET MVC project, for example.  Every time you collapse the node associated with the SecurityManager project, and you expand it later, you will see the same result as above.  This can be very frustrating when you have dozens of projects with their child nodes expanded in a similar way in Solution Explorer, and God forbid you have also expanded the References node, because it tends to visually pollute the Solution Explorer.  ReSharper 4.5 introduced a new feature that allows you to definitively collapse a node, be it a folder or the project node itself, so that the next time you expand the root node, the previously collapsed node stays closed!  This might sound like nothing, but have you ever calculated how many seconds you probably were wasting trying to navigate the Solution Explorer when you have a multitude of projects with folders, or solution folders, all open at the same time even though you don’t really need them to be?  That’s not being productive.  That’s not being professional.

So here’s the trick: when you’re done with one node and you need to collapse it for good, simply right-click on it in the Solution Explorer, and choose “Collapse All”.  This would permanently collapse the node until you explicitly expand it again.  For example, if I decide to execute this “Collapse All” command on the Users folder, then each time I expand the SecurityManager node, the Users folder will stay collapsed, until I explicitly expand it.  In my opinion, this should’ve been a standard option for Visual Studio.  Good thinking once again!

5. Inline field (Ctrl+Alt+N)

The fifth of my favorite new features in ReSharper 4.5 is the possibility to inline a field.  As to tweak the original Inline Temp refactoring definition to suit this one:

You have a field that is assigned to once with a simple expression, and the field is getting in the way of other refactorings.  Replace all references to that field with the expression.

I think that little definition sums it up well what Inline Field does.  Simply highlight the field, then hit the Ctrl+Alt+N shortcut, and you’re done.  Here’s a last example.  Suppose you have the following class definition:

As you can see, the someString field is used only once in this class, which is pretty much useless.  In that case, I will place my cursor on it, then hit Ctrl+Alt+N to have it inlined:

And that’s it! Now through all the code, the field’s expression will be inlined.  This was a simple scenario, but I’m sure you can think how useful this refactoring could be in your codebase.

[UPDATE: 2009-04-14] The Inline Field refactoring also works to inline methods and properties, not only fields! This is very sweet.  They should call this command Inline Construct as it doesn’t just inline fields.

But there’s more!!!

Of course, my list of favorite new features in ReSharper 4.5 isn’t the whole story behind this new release.  For a complete list of new feature in ReSharper 4.5, I’ll invite you to review its What’s New in ReSharper 4.5 features page. ReSharper is getting better and better through each release, and I can’t wait to see what the team is going to include in the 5.0 release.  But meanwhile, if you haven’t upgraded to this new version, I urge you to do so.  Plus, the upgrade is free if you’re already a ReSharper 4.x licensee, so you really have no excuse.  And if you’re not currently using ReSharper at all, then I hope that the following post has incited you to ask your tech lead or manager to get a license for it (I would suggest to start with the trial, then demo it to your group).  I’ll also invite you to read my post on The Case for ReSharper in the Enterprise which might give you some pointers on the necessity of this tool in your development toolbox.