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.

Comments (3)

  1. Rory says:

    Wow, man. That’s not terribly good news.

    I was hoping that VB had left problems with parens in the past…

    Call MySub(someArg, anotherArg) ‘OK, of course

    MySub someArg, anotherArg ‘Also OK

    MySub(someArg, anotherArg) ‘Not OK – WHY?

    This was one of my favorites from old school VB.

    I haven’t messed with VB.NET enough to know if it’s still like this.

    I just hope it isn’t.

    I wonder why it is that strange things happen with VB and parens… Weird, weird, weird.

  2. Kim Gräsman says:

    You’re forgetting one;

    MySub(singleArg) ‘ OK, surprisingly

    I’ve figured out that it’s because it’s a single argument, and it happens to be enclosed in parentheses, so the compiler accepts it.

Skip to main content