November 2005 - Posts
It's as simple as creating a static generic classMartin Shoemaker wrote a recent post on his blog discussing a number of issues he had migrating TabletUML from .NET 1.x to 2.0, specifically discussing moving to generic collections.
I'll add a couple suggestions that hopefully makes your migration easier.
First, Martin discusses a problem migrating this routine:
private void SelectMembers(
ArrayList members, ArrayList newSelection,
ArrayList selected, ArrayList unselected)
He choose to make the enclosing class (in his case, a Form) a generic class, and lamented that he could not create a generic method inside a non-generic class. I'd prefer moving that method out of the class and creating a new static class:
public static class SelectionUtilities < T >
{
public static void SelectMembers(
List<T> members,
List<T> newSelection,
List<T> selected,
List<T> unselected)
{
// contents elided.
}
}
I'm not certain it will work in Martin's case, because he did not include the full source to the original method. But, it sounds like no other member variables were affected, so this strategy works just fine.
Second, I want to clarify Martin's discussion of generics and SOAP serialization. Quite simply, it's a bug, not a practical limitation of SOAP. You would not be able to serialize a generic class, but that's ok: you can't instantiate one either. However, you should be able to serialize a specific instance of a generic type. By this I mean that you can't serialize List<T>, but List<string> should be no problem.
Microsoft has acknowledged this problem and has mentioned that the SOAP serializer will be deprecated with the Indigo, WCF XML Formatter. See here for the details: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=147645&SiteID=1
Personally, I don't agree with the decision to drop support for the SOAP formatter before WCF is completed.
I've finished my term as presidentLast week we held our annual elections at the Great Lakes Area .NET User Group (www.migang.org). Well, after two years as president, I'm more than happy to let someone else take the reins. I'm glad that John Hopkins (http://www.dotnetrockstar.com/) was interested in stepping up to the challenge.
John has been our treasurer for the last three years, and I'm sure he'll do a wonderful job. He'll have some new ideas, and he is already helping to make sure we continue withe all the programs that have been successful. I think it will be a great year.
Oh, and I'm not completely going away. I'm taking over for Josh Holmes (http://www.srtsolutions.com/public/blog/19990) as Program Chair.
The best of last week's information on the webI found myself very busy last week. So, I kept bookmarking different items that looked very interesting. I finally got around to them this weekend. Here they are:
C# VB.NET TranslatorThis site translates between VB.NET and C# code
Getting Started with Windows Forms 2.0 (Yes, there is a lot that's new)JFO's coding post about samples using the new Windows Forms library
More JFO's Coding: Changing the colors of toolstripsCause you never know when you might need it.
How to build for 1.1 when you're using 2.0Jomo Fisher posts about how to use VS.NET (and MSBuild) 2.0 to target 1.1
The differences are subtle.The difference between mutable readonly properties and read-write properties seems to confound even more experienced .NET developers.
So, I’m going to post a short quiz about the differences. Tomorrow I’ll post the answers, and discuss why those differences are important.
The quiz is simple. Write the output generated by each GenerateOutput() method call in the following code:
classLister
{
private readonly IEnumerable<string> theList;
public Lister(IEnumerable<string> srcList)
{
theList = srcList;
}
public void GenerateOutput()
{
foreach (string s in theList)
Console.WriteLine(s);
}
}
class SampleClassOne
{
privateList<string> words = new List<string>();
public IList<string> Words
{
get { return words; }
}
}
class SampleClassTwo
{
private List<string> words = new List<string>();
public List<string> Words
{
get { return words; }
set { words = value; }
}
}
static void Main(string[] args)
{
// First example: mutable property:
SampleClassOne exampleOne = new SampleClassOne();
Lister observer = new Lister(exampleOne.Words);
exampleOne.Words.Add("This");
exampleOne.Words.Add("example");
exampleOne.Words.Add("works!");
Console.WriteLine("First output");
observer.GenerateOutput();
// make more changes:
exampleOne.Words.Clear();
exampleOne.Words.Add("Another");
exampleOne.Words.Add("example");
exampleOne.Words.Add("working!");
Console.WriteLine("second output");
observer.GenerateOutput();
//////////////////////////////////
// Second example: read/write property
SampleClassTwo exampleTwo = new SampleClassTwo();
exampleTwo.Words.Add("This");
exampleTwo.Words.Add("example");
exampleTwo.Words.Add("works too!");
Lister otherObserver = new Lister(exampleTwo.Words);
Console.WriteLine("third output");
otherObserver.GenerateOutput();
// Make changes the right way:
exampleTwo.Words.Add("Another");
exampleTwo.Words.Add("example");
exampleTwo.Words.Add("working!");
Console.WriteLine("fourth output");
otherObserver.GenerateOutput();
List<string> tmp = new List<string>();
tmp.Add("this");
tmp.Add("is");
tmp.Add("a");
tmp.Add("set");
tmp.Add("of");
tmp.Add("new");
tmp.Add("keywords");
exampleTwo.Words = tmp;
Console.WriteLine("fifth output");
otherObserver.GenerateOutput();
}
Try and figure it out without putting it in VS.NET. Exercise your brain, not your compiler.
Does the size of your employer affect your relationship with customers?I’ve had a number of social and business meetings over the past few weeks, and I’ve got an interesting observation about company size and focus. Maybe, just maybe, this is why we have more growth from small companies.
Everyone attending these networking meetings asks each other about their job. The overwhelming number of people that work for small companies discuss what they do for customers. Employees at large companies talk about what they do for their employer.
The difference is more striking for key individuals at large and small firms. Principals and officers in small firms discuss what they do to provide business value for customers: raise revenue, lower cost, improve productivity, or anything else. Principals at larger firms discuss how they provide business value for their own firm.
Does this focus put larger firms at a disadvantage? I’m not sure. But I am convinced that it does put the customers of larger firms at a disadvantage some of the time. If your vendor is more concerned about making money for themselves than saving money for you, you’re in trouble.
I’m not sure how this happens, but it’s something to think about. Can smaller companies (like ours) use this to our advantage? Is better service that measurable? Is it possible for larger companies to stay focused on the customer? Or, if you have to make quarterly numbers repeatedly, does your focus shift from creating happy customers to creating happy managers? And, is there a better way to measure the contributions of employees at larger companies?
I’d like your thoughts. Have you observed the same phenomenon? If so, do you have different views?
Game programming with KPLI found this article tonight on CodingForFun: Creating the classic PONG game using KPL (kids programming language) for .NET
My son is getting interested in game programming, so I'll see if he wants to give it a shot tomorrow.
Coding for Fun: KPL PongThe one where you can learn how to waste even more time writing games