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.
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 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".
Logging 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 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.
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).
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.
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?
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):
Here is a pop quiz for language aficionados.
Examine the following class:
Now examine the following console mode program:
Without using a compiler, do you know:
Now, examine the same console program in VB:
Bonus third question:
I was suprised by the answer to the last question ...
The skill of writing is to create a context in which other people can think.
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…
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.
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…
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.