More automatically please!

The nine most terrifying words in the English language are, ‘I’m from the government and I’m here to help.
Ronald Reagan
40th president of US (1911 – 2004)

 

It never fails to surprise me when software does not do something that it is smart enough to do – but doesn’t.  In the midst of writing some code to enumerate the folders on the CF card for the FEZ Panda II, Visual Studio 2010 was kind enough to give me the following errors.

Here is the code

Visual Studio Error - the name 'Directory' does not exist in the current context

Visual Studio Error - variable 'Directory' does not exist

 

When I looked up the reference on MSDN to discover that it was in the System.IO namespace and the  mscorelib assembly.  However VS still generated the error.  Turns out that I needed to add the SystemIO reference.  As the frustration faded, I  began forming theories about why didn’t VS automatically add the Using statement with the proper reference into the project.  Realized that in theory I might be talking about another implementation.  However, the error should have at least offered a recommendation for the best default implement.

using System;

using System.IO;

using System.Threading;

using Microsoft.SPOT;

using Microsoft.SPOT.IO;

using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;

using GHIElectronics.NETMF.IO;

namespace DebugTest

{

    public class Program

    {

        public static void Main()

        {

            // Blink board LED

            bool ledState = false;

            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);

            Debug.Print(Resources.GetString(Resources.StringResources.String1));

            Debug.Print("Amazing!");

            //---------------------------------------------------------------------------------------

            // SD Card is inserted

            // Create a new storage device

            PersistentStorage sdPS = new PersistentStorage("SD");

            // Mount the file system

            sdPS.MountFileSystem();

            // Assume one storage device is available, access it through 

            // Micro Framework and display available files and folders:

            Debug.Print("Getting files and folders:");

            if (VolumeInfo.GetVolumes()[0].IsFormatted)

            {

                string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;

                string[] files = Directory.GetFiles(rootDirectory);

                string[] folders = Directory.GetDirectories(rootDirectory);

                Debug.Print("Files available on " + rootDirectory + ":");

                for (int i = 0; i < files.Length; i++)

                    Debug.Print(files[i]);

                Debug.Print("Folders available on " + rootDirectory + ":");

                for (int i = 0; i < folders.Length; i++)

                    Debug.Print(folders[i]);

            }

            else

            {

                Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");

            }

            // Unmount

            sdPS.UnmountFileSystem();

            //-----------------------------------------------------------------------------------------------

            while (true)

            {

                // Sleep for 500 milliseconds

                Thread.Sleep(500);

                // toggle LED state

                ledState = !ledState;

                led.Write(ledState);

            }

        }

    }

}


Tags:

One Response to “More automatically please!”

  1. Shaun | August 28, 2011 at 9:16 pm #

    On the flip side, it never fails to annoy me when software THINKS it can do something automatically, and does something unexpected.

    Example 1: Writing code in an outlook email message and having it change capitalization or spelling.

    Example 2: When I sign my emails with “- Shaun” at the end, it makes the hypen into a bullet.

    I am not saying software shouldn’t be smarter, but it does increase the possibility you are going to annoy your users.

    I think the secret is to make sure it is easy to disable “smart” features temporarily, or at least undo their actions easily.

Leave a Reply