views:

459

answers:

5

Hello, friends

Who knows, why in vb.net WinForm projects the designer by default use the Friend WithEvents attributes and in C# - private ones.

By ex, in a form.designer.

.cs

private Label Label1;

.vb

Friend WithEvents Label1 as Label;

For WithEvents is more or less clear(for using Handles, apparently). But why Friend in VB and private in C#... Thanks.

A: 

Perhaps VB is trying to be Friendlier to new programmers and allow them to see all the Friend controls in the form from anywhere in their project?

Friend being internal, only thing I can think of, not sure why the defaults would be different other than to assist new programmers...

Aequitarum Custos
I believe the new programmers should think OOP, and learn its (Black)Box concept.
serhio
OOP is easy to preach, but even with C# many green developers learn just enough to get by and fall into a procedural approach. Proper OO design requires additional forethought and greater consideration, so naturally it's a skill that develops *after* learning the basics of an OO language.
STW
I agree, just one of many reasons I recommend C# to new programmers...
Aequitarum Custos
I actually offer VB.NET as the better "learning" language; it lets a new developer cut their teeth worrying less about syntax and higher-level design and more about learning the framework. Once a developer is competent with the basic framework tools then they can consider the design and security aspects; it makes for a natural breaking point to make the switch.
STW
+1  A: 

I think it is to help with migration from earlier versions of VB as code in the forms tended to be modified from outside more frequently. Friend is also the default.

Private is better from a code design perspective and is used in C# as there is no similar historic coding practice I guess!

DiggerMeUp
+4  A: 

Friend WithEvents is used for compatibility with older Visual Basic code, where normally a control was used outside the form which contained it.
Differently, in C# there is not the need to keep the compatibility with old code code, which doesn't exist.

private is a better solution, for new code.

kiamlaluno
+3  A: 

Typically VB.NET leans towards exposing too much (privacy is mostly opt-in) whereas C# is the inverse, privacy is typically opt-out. As others have mentioned the reason is likely due to VB.NET's legacy and the "friendliness" of exposing everything; it makes it easy to get started but also leads to poor design and additional effort to ensure loose coupling.

STW
A: 

Anyone know how to make VB default to Private for new forms and user controls??

Darrren
You don't have to edit the code to do this, there's a "modifiers"property in the properties window for this.
serhio
by the way, this is not an answer, so you should start a new question for this, or, if you want, I could include your question in mine and reopen it.
serhio
Thanks, have got round to starting a new question here:http://stackoverflow.com/questions/2800618/set-a-project-default-for-vb-net-projects-so-that-the-default-modifiers-property
Darrren