Constructor Parentheses

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Tea

When creating an object instance like thi

Dim foo As New clsBar(

the current VB.NET documentaion says that the parentheses are optional if there are no constructor parameters

In version 2002 Visual Studio it will always insert the parentheses if you forget them, however, more annoyingly, in version 2003 it will always take them away if you type them, even though the code examples in the Help show parentheses

To say they are "optional" is therefore not true for either version

Call me anal, but I'm teaching this stuff and hate this willy-nilly bending of the syntax with each new edition of the product. Is there perhaps a switch somewhere that controls this behaviour of the editor? (Or is this just another case of wooing ex-VB6 programmers into VB.NET, because they never needed parentheses anyway?) Interestingly, parameterless non-constructor method calls still require parentheses, even in version 2003. Maybe they'll clobber that in the next version ;

Any suggestions

Cheer
Matthias
 
* "=?Utf-8?B?TWF0dGhpYXM=?= said:
When creating an object instance like this

Dim foo As New clsBar()

the current VB.NET documentaion says that the parentheses are optional if there are no constructor parameters.

In version 2002 Visual Studio it will always insert the parentheses if you forget them, however, more annoyingly, in version 2003 it will always take them away if you type them, even though the code examples in the Help show parentheses!

To say they are "optional" is therefore not true for either version.

I hate VS.NET 2003 for removing the '()' in a call to a parameterless
ctor. AFAIK this "feature" has been introduced to remove ambiguity for
beginners with array declarations vs. ctor calls:
 
I hate VS.NET 2003 for removing the '()' in a call to a parameterless
ctor. AFAIK this "feature" has been introduced to remove ambiguity for
beginners with array declarations vs. ctor calls:

I would point out that this is a feature of the *IDE*. If you typed your
program using notepad and compiled it with VBC, it would not remove your
parentheses. So the documentation is correct in that the parentheses are
optional for the *language*, but the IDE decides to remove them for you.
 
Chris,

* Chris Dunaway said:
I would point out that this is a feature of the *IDE*. If you typed your
program using notepad and compiled it with VBC, it would not remove your
parentheses. So the documentation is correct in that the parentheses are
optional for the *language*, but the IDE decides to remove them for you.

ACK. That's why I wrote "ambiguity for beginners", there is no
ambiguity for the compiler. I would like to have more control over how
VS.NET formats the source code.
 
Matthias,
You can get VS.NET 2003 to leave the () on the constructor call, by clicking
UNDO immediately after it removes them. Unfortunately sometimes you need to
UNDO two or three times.

The problem with doing this, if you ever change that line (directly or
indirectly) the () will come back...

I suspect (have not tested) that if you turn AutoFormat off, then the ()
will stay.

I too really don't like the idea of having them removed, however I've grown
accustomed to them not being there...

Hope this helps
Jay

Matthias said:
Hi Team

When creating an object instance like this

Dim foo As New clsBar()

the current VB.NET documentaion says that the parentheses are optional if
there are no constructor parameters.
In version 2002 Visual Studio it will always insert the parentheses if you
forget them, however, more annoyingly, in version 2003 it will always take
them away if you type them, even though the code examples in the Help show
parentheses!
To say they are "optional" is therefore not true for either version.

Call me anal, but I'm teaching this stuff and hate this willy-nilly
bending of the syntax with each new edition of the product. Is there
perhaps a switch somewhere that controls this behaviour of the editor? (Or
is this just another case of wooing ex-VB6 programmers into VB.NET, because
they never needed parentheses anyway?) Interestingly, parameterless
non-constructor method calls still require parentheses, even in version
2003. Maybe they'll clobber that in the next version ;)
 
Back
Top