Good afternoon all! I like this idea of thinking that I'm talking to a bunch of people as I type this, so I'm just going to go with it as I take my notes. Yesterday I went over how to create a new Console project in Visual Studios, and gave a basic overview of your workspace. Today I would like to start looking at some of the code.
To move ahead quickly, here is the full Hello World program code:
You need to understand the second line of code before I can explain the first line, so for now ignore the Imports
What is a Namespace?
The Namespace feature in VB.NET is a more detailed naming system. To understand things I like to relate them to real world examples instead of how they relate to other code examples, so let me take a crack at explaining Namespaces this way.
My name is Jarid. I have an odd spelling of the name, so no one mistakes me for the Jared from the Subway commercials, and no one can say they came to me for great jewelry. On paper this is all the the of us would need to know when someone is referring to me instead of one of the famous guys. Spoken our names sound the same, so all 3 of us would look to who was calling us. Enter the last name concept. Mine is Lawson, and while I like to think that back in the day someone earned this name in my family because their father was in law enforcement of some sort (and I can directly relate to that since my father was an officer for 20 years), that is the least important aspect of a last name in my example. Call out in any format - first, last; last, first; a mixture, first, last initial (granted this is less effective because there is a 1 in 26 chance you can have a duplicate still) - it still works to reduce calling 2 people when only 1 is needed.
Computers are less forgiving than humans are when a call for a specific name is made. Whatever the object being called may be - variable, class, function, etc. - no 2 objects can have the same name. If you are working with a large program (thus likely on a large team of programmers) you are likely to have times when the same name is used for 2 classes or 2 variables. Namespaces takes care of that.
Namespaces are the Last Names of an object. The difference in formatting for most Americans is seeing the last name first, but I believe several Asian cultures use this format for the names of their people (or I heard the announcer on G4's Ninja Warrior way wrong...snooge). In any case...my name in object oriented code form would be Lawson.Jarid. If you wanted to refer to the glasses I'm wearing, you could go so far as to say the object Jarid in namespace Lawson now becomes its own Namespace; thus the glasses name would be Lawson.Jarid.Glasses or lAwSoN.jArId.GLasSEs if you want to write it in annoying poser-hacker form.
What this means is a namespace is simply a collection of objects (variables, properties, classes, etc.). The namespaces can have sub or child namespaces, and they can also be part of higher level or parent namespaces. They keep it all in the family. That way when you call MyHellowWorldApplicationns.MyHelloWorldModule, the system knows that is different than YourHelloWorldApplicationns.MyHelloWorldModule.
Ok, these take a little longer than I thought they would to write. I had thought I would get through the entire explanation of the code today, but alas it is not to be. Your assignment, should you choose to accept it, is to take another look at the code, and see it in the namespace identification format that the computer does. Really pay attention to the objects and how they relate to one another, and understand that there are still a ton of subtle concepts shown here that I just haven't been able to get to yet.
Have a great weekend, and I'll see you Monday with the next lesson: The Imports Keyword