Results 1 to 11 of 11

Thread: how to learn or familiarize with the namespaces

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2013
    Posts
    1,126

    how to learn or familiarize with the namespaces

    When you are a Windows guy, more or less you know where you files are and why is it there placed or installed.
    When you are new to Linux OS, the structure of the files and folder directory is not the same with Windows thus you least know where you files are located, in what folder or in what partition.

    So you google the Linux directory structure and its explanation.

    I guess most of non-experienced Visual Studio or .NET users are not familiar with these namespaces,

    What they are,
    Why are they created like that,
    Where are those namespaces can be get and used
    When to use them and
    How to use them.

    Unlike vb6, when you create and use an object like form, immediately there is the available object pane, the available procedures pane, the available properties in the properties window in the visual basic form and code designer.

    But in visual studio, its somewhat different, the object pane and the procedures pane will only have their values when you created it on your code, so its not given unlike the previous vb6.

    What I am trying to say is, since there is difference then it should be learned and I am hoping to know more about namespaces:

    What they are,
    Why are they created like that,
    Where are those namespaces can be get and used
    When to use them and
    How to use them.

    I know it will be a long time to learn for newbies but I guess there would be some short crash course to get to familiarize with it. Thanks for understanding.

    .

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: how to learn or familiarize with the namespaces

    Quote Originally Posted by codesearcher View Post
    What they are
    A namespace is simply a logical classification of types in which all names are unique.
    Quote Originally Posted by codesearcher View Post
    Why are they created like that
    A namespace generally contains types that all have related functionality, e.g. the System.Windows.Forms namespace contains all the types that are specific to Windows Forms.
    Quote Originally Posted by codesearcher View Post
    Where are those namespaces can be get and used
    Namespaces don't exist in any specific place. This is where your idea of what namespaces are starts to go off the rails. Asking where a namespace is is like asking where mammals are. Mammal is a classification of animals and every animal that has the appropriate attributes is considered a mammal but that doesn't mean that the mammal classification exists anywhere specific.
    Quote Originally Posted by codesearcher View Post
    When to use them
    You don't use a namespace.
    Quote Originally Posted by codesearcher View Post
    How to use them.
    You don't use a namespace.

    You need to forget this fascination with namespaces. They are not especially important, or not in the way that you seem to think anyway. What matters is types, i.e. classes, structures, enumerations, delegates and modules. You use the type that is appropriate for the task at hand. Each and every type you use is a member of a namespace so, if you want to think of it that way, you're using a namespace whenever you use a type that is a member of that namespace. For a bit more information, I would suggest that you follow the Blog link in my signature below and check out my post on Assemblies & Namespaces.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: how to learn or familiarize with the namespaces

    To emphasize something JMC said, but in a different way: Don't worry too much about namespaces. In the end, they were really just added because of name collision. Two people might both create a class called Widget. In such a case, they can't both be used in a project because the compiler can't know which class to use. One solution to this is to require that one of the people change the name from Widget to WidgetA, or something like that, but that isn't a reasonable solution. Instead, namespaces were added to solve this. The first person could create a namespace like MyStuff, in which case the full name of their Widget class would be MyStuff.Widget. The other person might create a namespace like Bubba, in which case the full name of their Widget class would be Bubba.Widget.

    When you have an OO language, you just run into the case that people create loads of types (classes and structures) and sometimes different people will create types with the same names. Namespaces are just a way to more specifically identify a specific type.
    My usual boring signature: Nothing

  4. #4
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: how to learn or familiarize with the namespaces

    You may not know it, but VS is automatically making namespaces for you based on your project name and its folder structure. You can manually define namespaces for your files, but if your project isn't something like 50+ different code files you probably don't approach a complexity where it matters.

    So if you make a project named "MyCalculator", everything in the project is automatically placed in the namespace "MyCalculator" by VB. If you add a folder named "Settings" to the project, any files you put in that folder will be in the namespace "MyCalculator.Settings", and so on. I've been on some very large projects with millions of lines of code. I have almost never seen a situation where this default wasn't what I wanted, and I don't want to talk about the exception where it mattered at all.

    But, if you want a crash course for how to do it yourself, it's fairly easy. The average file looks like this:
    Code:
    Public Class MyForm
        Inherits Form
    
        ' Code
    
    End Class
    To change the namespace of the file, you add a Namespace Statement Block around the Class. Note it has to go after any Imports statements that might exist:
    Code:
    Imports System.Windows.Forms
    
    Namespace MyCalculator.Settings
    
        Public Class MyForm
            Inherits Form
    
            ' code
    
        End Class
    
    End Namespace
    That's really it. Now the form's fully-qualified name will be: "MyCalculator.Settings.MyForm". It 'belongs' to the "MyCalculator.Settings" namespace, so other files in the project need "Imports MyCalculator.Settings" to see it. This is really useful if, for some reason, you have two types that need to have the same name. But most of the time you can also solve that problem with more specific names, sort of like how the MSSQL connection object is "SqlConnection" and the ODBC one is "OdbcConnection", even though they're in separate namespaces.

    So, in actuality, in making this post you've thought about namespaces about 10x harder than most experts do. Even experts who use C#, where you are required to declare a namespace in every file. On that side of the pond, VS auto-generates the namespace line and 99% of the time we don't touch it.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    May 2013
    Posts
    1,126

    Re: how to learn or familiarize with the namespaces

    Thanks for the replies guy. On ther other hand may I specifically ask about this imports statement for namespaces like

    Imports System.Collections.Generic

    So the namespace used here is from System. How will I know those different namespaces like System and when to use them.

    Is there an article to read about them?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: how to learn or familiarize with the namespaces

    Quote Originally Posted by codesearcher View Post
    Thanks for the replies guy. On ther other hand may I specifically ask about this imports statement for namespaces like

    Imports System.Collections.Generic

    So the namespace used here is from System. How will I know those different namespaces like System and when to use them.

    Is there an article to read about them?
    Again, it's types that matter. All you need to know is what type you need to use in a particular situation. The MSDN documentation for every type tells you at the top what assembly it's declared in and what namespace it's a member of. I specifically mention that in the blog post I directed you to 24 hours ago. If you're so keen for information then I have to wonder why you haven't read it yet.

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: how to learn or familiarize with the namespaces

    Quote Originally Posted by codesearcher View Post
    Thanks for the replies guy. On ther other hand may I specifically ask about this imports statement for namespaces like

    Imports System.Collections.Generic

    So the namespace used here is from System. How will I know those different namespaces like System and when to use them.

    Is there an article to read about them?
    Well, for starters (and I'm a tad surprised jmc didn't touch on this) the Imports isn't even necessary. It's just a shortcut mechanism for the developer to save on typing. All it does is save on the amount of typing one has to do to access something within the imported namespace. that is all.

    You use the system namespace when the class you do want to use is in the system namespace. How do you know when to use it? You learn. After a while of exploring MSDN and the namespaces when entering code... after sometime, you simply develop a sense of these things. Just about everything starts with System.

    Let's say I'm doing stuff with paths... and I need to concatenate some path parts together. Back in the old days, I'd simply put everything into a string and concatenated them together. With .NET I knew there should be a better way. I come across Path.Combine ... Combine is a function in the Path class, that's in the IO namespace that is in the System namespace. After using it twice, I now just know that when I combine two parts of a path together I just start typing System.IO.Path.Combine, and viola! there it is. Unless I Import System.IO ... then it's just Path.Combine .... what I CANNOT do is Import System.Io.Path... because Path is a class, not a namespace.

    And that's all it really is... just learning by practice practice practice.

    For the stuff I work with in our application domain... for product items it's CompanyName.Product.Area.Form.Functionality ... for custom elements it's CompanyName.Custom.Area.Form.Functionality ... So if I'm working on something in the GL area... it's CompanyName.Product.Revenue.PostToGL... and so on...

    meh... I've probably muddled it even more...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: how to learn or familiarize with the namespaces

    Quote Originally Posted by techgnome View Post
    Well, for starters (and I'm a tad surprised jmc didn't touch on this) the Imports isn't even necessary.
    You'll never guess. I address that in my blog post.
    Importing a namespace is never necessary and simply allows you to use types that are members of that namespace without qualifying the name.

  9. #9
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: how to learn or familiarize with the namespaces

    hehehe.... you wrote:
    The MSDN documentation for every type tells you at the top what assembly it's declared in and what namespace it's a member of. I specifically mention that in the blog post I directed you to 24 hours ago. If you're so keen for information then I have to wonder why you haven't read it yet.
    I read
    The MSDN documentation for every type tells you at the top what assembly it's declared in and what namespace it's a member of. If you're so keen for information then I have to wonder why you haven't read it yet.
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: how to learn or familiarize with the namespaces

    Quote Originally Posted by codesearcher View Post
    Thanks for the replies guy. On ther other hand may I specifically ask about this imports statement for namespaces like

    Imports System.Collections.Generic

    So the namespace used here is from System. How will I know those different namespaces like System and when to use them.

    Is there an article to read about them?
    I'm sure you'd rather someone answer your question without veiled insults.

    When you want to do a thing, the first question to ask is, "Has Microsoft provided stuff to do this for me already?" Sometimes the answer is 'yes'. A search engine's the first place to ask, a forum's the last. If you ask on a forum, you tend to get answers from grouchy experts who make fun of you for asking questions, because there's absolutely no way search results can be a bit confusing to newbies, and people "need to learn" to be self-sufficient. (Which is really odd, because then the same people berate other posts for 'providing a tutorial' instead of 'just solve the problem'.)

    So you find some class that does what you want. The next step is to make sure you're looking at its documentation page on MSDN. The easy way to do that is put "msdn TheClassName" into a search engine, and usually the result is right at the top. On that page, you'll get the name of the class, the namespace, and the assembly it's in in case you need to reference it.

    The only way to "learn" them is to just write a lot of code and get used to where things are. There are lists of namespaces on MSDN, but there's at least a thousand of them and most people never use more than two dozen. So it's a waste of time to try and learn them all, you'll end up cluttering your mind with things you don't need and spending time learning things you won't use.

    You'll also tend to find examples and explanations of what the class is used for on MSDN. Always give them a skim before asking further questions on a forum. You can stop most of the grouches from laughing and saying "read the documentation" if you point out "I read it, but I don't get what this paragraph means" or "I read it, and it doesn't say what I want, did I miss something?" This is generally a good idea even when not dealing with grouches: sometimes the question sounds like something that's right there in the documentation, but when you point out what you feel is missing it becomes clear you're asking something else entirely.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: how to learn or familiarize with the namespaces

    Quote Originally Posted by Sitten Spynne View Post
    I'm sure you'd rather someone answer your question without veiled insults.
    Maybe people get grouchy not because someone hasn't bothered to search the web or read the documentation, although that's a fair enough reason, but rather because they have directed someone to a specific piece of information that they haven't bothered to look at. Maybe they get grouchy because they've written that information themselves to help people who have questions so that they and others don't have to keep repeating the same things over and over but, rather than make the effort to read it, someone asks for that same information to be repeated yet again. I'm just guessing of course.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width