OdeToCode IC Logo

5 Things To Do With A Big, Fast Flash Drive

Friday, May 4, 2007 by scott
  1. Save some time installing Vista. Kurt Shintaku describes how to format a bootable flash drive with the contents of the Vista DVD. If your machine can boot from a USB device, this approach does shave some time off the Vista install.
  2. Improve Vista performance with ReadyBoost. ReadyBoost allows Vista to use a fast USB memory device as an intermediate caching area between memory and disk. Tom Archer has a ReadyBoost Q&A with the technical details.
  3. Carry a suite of portable applications. PortableApps.com packages a browser, email client, backup utility and more configured to work from any USB memory device. The standard suite of applications fills over 260MB of a flash drive with portable goodness. Relying on special technology, U3 provides portable apps for U3 smart drives.
  4. Run a different operating system. Live USBs, like Live CDs, are bootable flash drives with an operating system installed. Wikipedia's list of LiveDistros contains many Windows, *nix, Apple, and DOS distributions that fit on a key.
  5. Save some time installing Visual Studio. I've done this, and I learned one trick: the flash drive has to have the name "DVD1" for an MSDN installation to complete successfully. See Aaron Stebner's post for more DVD naming schemes.

What Was Wrong With #15?

Thursday, May 3, 2007 by scott

Not many takers on WWWTC #15, but Jason finally nailed it.

The bug in the code revolves around how VB allocates arrays. The following code snippet creates an array of 5 System.Char objects, and will output the number 5 to the screen, right?

Dim length As Integer = 5
Dim chars() As Char = New Char(length) {}


Console.WriteLine(chars.Length)

 The output is "6", which still astonishes those of us (me, at least) who hail from the land of semicolons. The number I pass to the New clause in VB doesn't specify the number of elements in the array, but the upper bounds of the array. Passing a 5 tells VB to create an array with 6 elements indexed 0 to 5.

I suspect this behavior is a compromise over the definition of an array's lower bound. Does an array start at 0? Does an array start at 1? It's a religious debate, but a VB developer could use the chars array like so:

For i As Integer = 0 To 4
    Console.WriteLine(chars(i))
Next

... or like so:

For i As Integer = 1 To 5
    Console.WriteLine(chars(i))
Next

... and neither will fail with an index out of bounds exception.

This behavior does cause a problem, however, when you want a precise number of characters and forget how New works. The unit test failed because it expected to get back a string with a length of 6 ("edoCoTedO"), but the actual string had a length of 7 (with a 0 character tacked on the end).

The fix is to create the array by passing the length of the string minus 1.

Groove versus FolderShare

Wednesday, May 2, 2007 by scott

I've been running FolderShare (a Windows Live Service) and Microsoft Groove (part of Microsoft Office 2007) concurrently for the last few weeks. Both products are Microsoft offerings, and both provide file synchronization features.

Which one do I like better?

FolderShare

FolderShare is lightweight and "just works". For over one year now I've been synching documents, IE favorites, OneNote notebooks, and scripts across 4 different machines with no issues. FolderShare creates a secure P2P network to perform the exchanges, and the only limitation I know of is the file size limitation (no files over 2GB).

All you'll see of FolderShare on your desktop is an icon in the taskbar notification area. All the sharing configuration takes place inside the web UI of FolderShare.com. Setup is simple, and there are no knobs to tweak and twiddle. The notification icon can give you some transfer statistics and tell you what is currently "in process".

Access file with 

FolderShareLogging into FolderShare.com gives you the ability to download any file (not just the files in shared folders) from any of your computers that are online and running the FolderShare application. This feature has proven useful to me more than once, however, I'm sure some of you are having cardiac arrest at this moment by picturing your CFO downloading PPT files using a public computer with a keylogger installed.

FolderShare is smooth and simple.

Groove

Groove is geared towards enterprise level collaboration, and as such is a bit heavy handed. For personal synchronization of files, Groove is overkill. If you are working with a team and need to manage contacts, store and forward messages, configure alerts, and manage multiple identities - then the rich client interface of Groove will give you more features than FolderShare.

Groove

The downside is – sometimes I notice Groove is running (noticeable CPU and memory consumption during large synchs), and at least once I noticed Groove was not running – at least it wasn't synching files. Repeated tapping on the computer didn't fix this problem (it never fixes any software problems, but the physicality is therapeutic). Bits didn't start flowing until I restarted Groove.

Groove uses its own Simple Symmetrical Transmission Protocol (SSTP) for secure P2P exchanges, although it appears it can also deliver a payload over HTTP (using a corporate Groove Server).

Is FolderShare The Future?

FolderShare is all I need for personal use, but I wonder what will become of the product. There haven't been any noticeable changes to the software since Microsoft acquired the creators (ByteTaxi) in November 2005. The software is still listed as "beta" and the site contains copyright notices for ByteTaxi Inc. It would be wonderful if such a simple, easy technology was baked right into the OS.

What's Wrong With This Code? (#15)

Tuesday, May 1, 2007 by scott

Mortimer is taking up TDD, and starts a new project by writing the following test.

<TestMethod()> _
Public Sub CanReverseString()

    Dim input As String = "OdeToCode"
    Dim result As String = Utility.ReverseString(input)
    Assert.AreEqual("edoCoTedO", result)

End Sub

Yes, it's another one of those big projects that reverses strings all the time.

With a test in place, Mortimer writes the following stub.

Public Class Utility
    Public Shared Function ReverseString( _
        ByVal input As String) As String
 
        Return Nothing

    End Function
End Class

Good news - the test fails! Now it's time to provide a real implementation...

Public Class Utility
    Public Shared Function ReverseString( _
        ByVal input As String) As String

        Dim chars As Char()
        chars = New Char(input.Length) {}

        For i As Integer = 0 To input.Length - 1
            chars(i) = input(input.Length - i - 1)
        Next

        Return New String(chars)

    End Function
End Class

Mortimer thinks he has everything straight - but the test still fails! What could be wrong with Mortimer's ReverseString?

The .Net Days Of Old

Monday, April 30, 2007 by scott

My association with .NET started over 6 years ago. In those early days I used C++ and COM as a point of reference for everything I was learning in .NET and C#. Destructors versus finalizers, Assembly.Load versus LoadLibrary, Metadata versus COM+ attributes, and of course - memory leaks versus managed heaps.

Those were fun times.

I'm gearing up for a customized Pluralsight class that includes material from the Applied .NET and Applied ASP.NET 2.0 courses. I also need some perspective of a Visual Basic 6.0 developer in a .NET land.

This reading list helps to re-live the days of old (from a VB6 perspective):

Looping 101

Sunday, April 29, 2007 by scott

Here is a pop quiz for language aficionados.

Examine the following class:

public class Foo
{
   
public int GetUpperLimit()
    {
        Console.WriteLine(
"GetUpperLimit invoked");
       
return 5;
    }

   
public IEnumerable<int> GetCollection()
    {
        Console.WriteLine(
"GetCollection invoked");
       
return new int[] { 1, 2, 3, 4, 5 };
    }
}

Now examine the following console mode program:

class Program
{
   
static void Main(string[] args)
    {
       
Foo foo = new Foo();

       
for (int i = 1; i <= foo.GetUpperLimit(); i++)
        {
           
Console.WriteLine(i);
        }

       
foreach (int i in foo.GetCollection())
        {
           
Console.WriteLine(i);
        }
    }
}

 Without using a compiler, do you know:  

  • How many times "GetUpperLimit invoked" will appear in the output?
  • How many times "GetCollection invoked" will appear in the output?

Now, examine the same console program in VB:

Sub Main()
   
Dim foo As New Foo()

   
For i As Integer = 1 To foo.GetUpperLimit()
        Console.WriteLine(i)
   
Next

    For Each i As Integer In foo.GetCollection()
        Console.WriteLine(i)
   
Next
End
Sub

 Bonus third question:  

  • Will the output of the VB program be the same as the C# program?

I was suprised by the answer to the last question ...

Writing Technical Books

Saturday, April 28, 2007 by scott

The skill of writing is to create a context in which other people can think.

-- Edwin Schlossberg

Jeff Atwood presents a visual contrast of two WPF books in "How Not To Write A Technical Book". I haven't read either WPF book, but Jeff's post did provoke some thinking…

Color Me Code

It's amazingly difficult to read code in monochrome these days. Language keywords, program comments, and string literals all blur into lumps. There is now chance to scan the source code for the important bits. Unfortunately, many publishers are unwilling to accept the higher cost of full color printing (except for technical books in the higher-education market, where the consumer is a PHY 101 student and at the publisher's mercy). Most college textboxes are printed in full color, but full color computer text books are a rare find.

If we look at some currently shipping WPF books, we see they are all heavily discounted from their list price and fall into the same price range:

It seems that publishers are pricing their books based on the competition and not on the production costs. Shrinking margins don't bode well for features like color.

I Have a Tip for You

Another topic in Jeff's post was the use of sidebars and callouts. Some people love sidebars. I don't.

A good technical book makes me think. An even better technical book makes me get to the keyboard to try something. Books with colored sidebars on every page are telling me there is something more important to read and rarely make me think or code. Instead, I'm burning cycles on context switching.

Warning: In 5 billion years, the sun will run out of hydrogen and become a red giant. Make sure your offspring will be located at a safe distance.

I see sidebars used as a copout. The author gave up trying to work an important fact into the technology's storyline, and instead threw the content inside a cartoon box. To be fair, it's not the author's fault. All publishers encourage this behavior. I think the publishers want books to look more like the web…

Can I Get An Ad?

Books are competing with the web, to be certain. Magazines are, too. Many tech magazines are free because they are chocked full of ads. Perhaps book publishers will one day start including advertisements to offset the cost of color printing - I hope not.