Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I use the "My" namespace for in VB .NET?

Tags:

vb.net

I'm considering building a framework for VB.NET, and using the My namespace to plug it into VB seems like a reasonable idea. What is "My" used for?

like image 372
RoyOsherove Avatar asked Oct 12 '08 12:10

RoyOsherove


People also ask

What is the purpose of namespace in VB net?

Namespaces organize the objects defined in an assembly. Assemblies can contain multiple namespaces, which can in turn contain other namespaces. Namespaces prevent ambiguity and simplify references when using large groups of objects such as class libraries.

Which namespaces are used for accessing the data in VB net?

Net Framework belongs to the System Namespace. The "system" Namespace has built-in VB functionality and all other Namespaces are based on this "system" Namespace. We can access a member of a Namespace by using a dot(.)

What is default namespace in VB net?

VB.NET uses the name of your project (WindowsApplication1 for a standard forms application if you don't change it) as the default namespace.

What is a .NET namespace?

Namespaces are used to organize the classes. It helps to control the scope of methods and classes in larger . Net programming projects. In simpler words you can say that it provides a way to keep one set of names(like class names) different from other sets of names.


3 Answers

The purpose of My, as I understand it, is to be an easy shortcut to certain API tasks that are common but hard-to-find or hard-to-use. You probably shouldn't completely subsume your framework under My. (For one thing, C# people using your framework may get grouchy.)

Instead, you should design it as a normal framework. When you're finished, make a list of some common tasks that people might want to use your framework for. See whether any of those could be useful to have under My, especially where there are classes or methods that can be used in a number of ways, but they have one or two really common usages that can be abbreviated with My.

This article shows how to extend My, and it has a section at the end that describes a few design guidelines to follow: Simplify Common Tasks by Customizing the My Namespace

As to your main question, when coding in VB .NET, I use My as often as I can. It reduces a number of operations to one line of code.

like image 172
Ryan Lundy Avatar answered Oct 27 '22 09:10

Ryan Lundy


I really like the "My" Namespace in VB.NET and I always use it in my WindowsForms applications, because it is very intuitive.

I use primarily these categories:

  • My.Computer: primarily for file system and network purposes
  • My.Application: Version number, current directory
  • My.Resources: Access to resources used by the application residing in resource files in a strongly typed manner.
  • My.Settings: very handy

I think, if your extensions for My of your framework fit well, then many VB.NET programmers would appreciate them.

like image 29
splattne Avatar answered Oct 27 '22 10:10

splattne


I've used My in my VB.NET projects, and I don't feel guilty about it. I am primarily a C# guy, but until I transitioned my company to C#, we were a VB shop. In my mind, the My namespace is a nice piece of syntactic sugar. Just as I'm not embarrassed to use C#'s coalesce operator and other sugar, I'm not embarrassed to use VB's sugar, either. (To an extent; I won't use the classic VB functions that .NET still exposes.)

That said, never put anything in that namespace. It's Microsoft's namespace, and just as you wouldn't put anything under System nor Microsoft, don't put anything under My. It will cause confusion later on -- if not for you, then for others who maintain your code. Create your own namespace for your own code.

like image 34
John Rudy Avatar answered Oct 27 '22 09:10

John Rudy