VB 10 thoughts (part 3)
Posted
Sat, Oct 6 2007 12:54
by
bill
More language thoughts for VB10 (see part1 and part2 for earlier posts)
- Delegate combining and removing syntax
Today in VB if you write a Custom Event handler, you have to write some really long winded code to combine and remove delegates, such as :
Custom Event Click As EventHandler
AddHandler(ByVal value As EventHandler)
m_ClickEventHandler = DirectCast([Delegate].Combine(m_ClickEventHandler, value), EventHandler)
End AddHandler RemoveHandler(ByVal value As EventHandler)
m_ClickEventHandler = DirectCast([Delegate].Remove(m_ClickEventHandler, value), EventHandler)
End RemoveHandler
This really should be simple such as :
Custom Event Click As EventHandler
AddHandler(ByVal value As EventHandler)
m_ClickEventHandler += value
End AddHandler
RemoveHandler(ByVal value As EventHandler)
m_ClickEventHandler -= value
End RemoveHandler
- CObj allowed in Attributes
If you write a control or component that has a design time value that is an Enum, using the Systme.ComponentModel.DefaultValueAttribute on that property is a pain in VB. The DefaultValueAttribute has overloaded constructors for most of the intrinsic types, one for Object, and one where you specify the type and the value as a string. In C# you get to use the one that takes an object, allowing you to specify an enum value, and it works. In VB you have to use the one that takes a type and a string containing the value.. that's a real pain and any breaking changes in the Enum don't show up at compile time because it's a string. We should be allowed to use CObj on constant expressions in attributes.
- Static versus Shared
No, I'm not talking VB versus C#. VB actually has this correct whereas C#'s "static" is misleading, after all the value can change, so that's hardly "static" <g> What I am referring to is Static variables in VB. They are seldom used, and seldom understood. And the naming is inconsistent. It should be Shared, not static, as the variable is Shared amongst calls to that method. So just as Shard is used at class level, it is used at procedure level.
What I'd like to see is "Static" become obsolete and replaced with Shared. "static would still work, but a warning would be raised. And in the IDE is you typed static, it would replaced it with Shared for you (both at class level and procedure)