views:

266

answers:

4

For the last year and a half we've gotten been working on a large WPF application and it's finally exiting beta and moving to full release. When we started the project, I fought hard for every assembly to use Option Strict. My team had little .NET experience prior to this project, and alot of experience with Visual Basic 5 where nearly everything was a Variant in our old code. It took months to get everyone comfortable with things like casting and object oriented aspects of VB.NET. I also had to fight very hard to break everyone of Hungarian Notation.

Now that we're out of beta and beginning to work on new features, I'd like to start taking advantage of LINQ, but I fear that anonymous types in VB 9.0 will be thought of as variants, and my team will make a push to go back to Hungarian Notation. How can I get the point across that anonymous types aren't variants?

+2  A: 

If it looks like a Duck and quacks like a Duck, people will assume it's a Duck.

Show them in code specifically where an anonymous type does not act the same way as a variant. It doesn't actually matter that they are handled differently "under the hood" - they have to "act" differently to the developer.

Ron

Ron Savage
A: 

Well, always assuming that your coworkers aren't idiots and just not accustomed to strong typing, and also assumig that you've succeeded in convincing them of the benefits of strong typing, it shouldn't be too difficult.

In fact, they're getting the advantages of loose typing (= less to write, automatic type inference) without the downsides (= loss of intelli sense, loss of compiler support for error detection). Sell it as the best from both worlds and they should out of your palm.

Konrad Rudolph
Correct me if I'm wrong, buy it seems as though you mean to compare dynamic typing to strong typing rather than strong to weak.
Jason Baker
Not sure, since there are contradictory definitions; however, I mean the term as used in the Wikipedia article on “type system” (which, admittedly, is ill defined): VB with Option Strict Off is weakly typed since non-obvious implicit conversions may be performed.
Konrad Rudolph
+2  A: 

Simply compile some code and load the assembly in the .NET Reflector

It really helps to see for your self how syntax sugar like auto-properties, lambdas or anon types get compiled.

Rinat Abdullin
+1  A: 

What exactly would you prefix an anonymous type with in Hungarian notation - a question mark? To illustrate the difference between variants and a strongly typed (albeit, anonymous), I'd think it'd be sufficient to show them the compiler error that will occur when you try to reassign the variable.

To rid them of Hungarian notation, I'd suggest pointing out that:

  1. They're probably doing it wrong, and if they're not - then it's still a decent practice
  2. The VS IDE features of go to type, Intellisense, etc.
Mark Brackett