Monday, November 28, 2011

Lesson #3: Dissecting the First C# Program You Created

If you're still sticking around, I can say that you're showing quite the initiative. Looking at the views for these videos on MS's website, the first video has over 12,000 views, the second video has about 900, and the third has just under 600 (as of this posting).  I'm sure some people watched the first video out of curiosity, but video 3 is a third less than video 2. I'm not sure how much of that is because people found Bob's terminology to be a bit over their head or how much of it is that people just gave up.

If the last lesson was a bit much, the next video breaks down the "Hello World!" app.

It breaks down the various lines of code. I think this video would benefit from some real world comparisons to what he's talking about. He talks about how namespace, class, and Main work. I get the impression that a real-world example to that would be country, state, and city or book, chapter, and page. But I'm just speculating. I do feel that Bob may be giving more information than needed but it sounds like he'll cover that all later. On top of that, Bob talks about projects and solutions, but then goes on to say that it's not too important until we get further along. Because of that fact, I do kind of wish that he waited to talk about that sort of thing until we get to that point.

This video is the beginning of when I can see people getting confused or lost. Let's break down a lot of what Bob covers.

The simplest thing Bob talks about is the role of the semi-colon (;). His example of it being like a period is pretty good. It ends the thought.

Another thing he mentions is the curly braces ({}). He calls them something like containers. I think of them like one might use indentation on a to-do list.. For example:

  • Go to the hardware store
    • Get hammer
    • Get nails
    • Get duct tape
  • Go to the grocery store
    • Get milk
    • Get eggs
    • Get bread

It's clear that one gets the hammer, nails, and duct tape at the hardware store and the milk, eggs, and bread at the grocery store. Without the indentation, it's not so clear. That's especially true for a machine that has no understanding of hammers and eggs. We know the difference because we have a developed understanding. Computers don't have that. Computers are dumb. They have to have everything spelled out for them. If we were to use the curly braces like in C#, the list would look more like this:

Go to the hardware store
{
Get hammer
Get nails
Get duct tape
}
Go to the grocery store
{
Get milk
Get eggs
Get bread
}

The double quotes in this video define the difference between a series of characters compared to a particular letter or number. With C# (and Bob covers this in the future) a variable is like a variable in math. It represents something else. But with C#, a variable doesn't have to be a single letter. A variable can be named X like it is in algebra but can also be named something like initialValue.

So in other words,
Console.WriteLine("initialValue"); 
displays the characters initialValue on the screen. We saw this with the "Hello World" program

Console.WriteLine(initialValue); 
would display the value of the variable initialValue on the screen.

I put the lines of code in italics to differentiate them from anything else. It's not to say that the code in C# will be the same. I'll follow that throughout these posts.

But that breaks down a lot of this video. Once we get into variable declaration (a couple videos from now), we can really start creating real programs that people may find useful. I can't promise that they'll be very pretty.

No comments:

Post a Comment