Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  To parenthesize or not... Bug in VB.Net? (Monday, January 30, 2006)




Found the following interesting discussion in the Newsgroups:

To parenthesize or not... Bug in VB.Net?
by:Anonymous

Call me a purist or picky but... I've found 2 instances where VB.Net considers parenthesis optional. Consider the following property, sub, and function in VB.Net: Public Property TestProperty() As Integer Get Return 0 End Get Set(ByVal Value As Integer) End Set End Property Private Sub TestSub() ' Do nothing End Sub Private Function TestFunction() As Integer Return 0 End Function VB.Net allows the following syntax in calling the previous routines: 1. If Me.TestProperty = 0 Then... 'Looks ok 2. If Me.TestProperty() = 0 Then... 'Huh? 3. If Me.TestFunction() = 0 Then... 'Looks ok 4. If Me.TestFunction = 0 Then... 'Huh? 5. Me.TestSub() 'Looks ok The interesting thing is if you remove the "Me." in call #4, the IDE forces both parenthesis in the syntax. This leads me to believe #4 is a bug. This call SHOULD look like #3 because VB.Net now requires parenthesis on all sub/function calls with parameters. Why should the syntax be any different with a function call without parameters? The syntax in call #1 is consistent with the use of properties. However call #2 looks like a function call, not a property query. You could make a strong argument that this syntax is ok for two reasons. First, properties can contain processing code just like a sub or function. Second, VB.Net properties can take parameters just as a sub or function so they should include the parenthesis. My argument is either force one syntax or the other, but not both and not neither. I'd prefer to see #1 instead of #2 simply to tell that it a property that is being accessed as opposed to a function. To summarize, I believe call #4 is a bug which I'd like to see fixed. I believe there is a bug allowing the syntax of both calls #1 and #2. I'd like to see one or the other fixed. Are either of these considered bugs? Has anyone else seen this? I couldn't find any posts relating to this anomaly.

 Reply:
by:David Browne

  Consider the following property, sub, and function in VB.Net: Well you're certianly not a VB purist. Empty parameter lists are optional in VB, they always have been. There is no ambiguity in VB like there would be in C or C# since the function name without the parameter list is not used as a function pointer. VB has the addressOf operator for that. But you wouldn't be the first person to hold the opinion that VB is a bit sloppy looking. David

 Reply:
by:Cor Ligthert

 Hi David, A lot of other people have the opinion that C type languages are often very discipline acting as a puritan schoolteacher, who is not telling why however only that you should. :-) Cor

 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

  The '()' for calling parameterless methods or accessing parameterless properties are always optional. What you are experiencing may be caused by the IDE's pretty listing/reformatting feature. Did you try to compile the code using "VBC.EXE" with and without the parenthesis? -- Herfried K. Wagner;







 
Previous Posts
    - How to change the Color of a Toolbar?
    - How to pass Objects as type System.Object?
    - How to create a Username/Login Page?
    - Suggestions to increase the performance of searchi...
    - Where did my Dataset Go?
    - Password Filter DLL
    - An application framework for VB.NET
    - 'System.Net.WebException' - Strange Error
    - Dataset Tablenames <- SQLHelper
    - Add handlers to textboxes in a datagrid

Archives
    - 2006-01-01
    - 2006-01-08
    - 2006-01-15
    - 2006-01-22
    - 2006-01-29


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland