What the heck? More places parens aren’t required…

I work with the Boise .NET Developers User Group (NETDUG — gotta luv that name).  They’ve started an MCAD SIG, so I work the study guide labs along with them.  I wanted to do some cross-language inheritance from VB (parent) to C# (child), just to see how MustInherit, MustOverride, etc. in VB would force the issue in C#.

I was using Notepad as my editor, and as I typed my VB class I forgot to put the parens after a subroutine name, such as
Public Sub fNoAttributes
End Sub
(Simple repro example.)
I compiled the class, and what do you know… the VB .NET compiler allowed this method definition.  GROAN!  The VB .NET environment in VS.NET tacks the parens on there if you leave them off, knowing they should be there for consistency and all reasonableness.  But no, they’re not required by the VB.NET compiler.  Ugh.

I looked at the generated class using ILDASM and saw the method defined as
.method public instance void  fNoAttributes() cil managed
// Code size       3 (0x3)
.maxstack  8
IL_0000:  br.s       IL_0002
IL_0002:  ret
} // end of method Foo::fNoAttributes

Just for grins I removed the parens from a C# method (again, using notepad) and the C# compiler squawked at me.  Thank you, C# compiler writers!

I complained earlier about the VB.NET environment removing the parens from instance creation:
Dim f as New Foo

But for methods they tack parens on, even though the compiler doesn’t require them.

Heh.  What were those VB.NET guys smokin’?  Certainly not the consistency weed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s