Tuesday, July 10, 2007

Day 1- My First Over-Analyzation of a Hello World Application


This LINK may be easier to read, made into an html Doc



So first we will go through the confusing documentation, and i am here to dumb it down, for myself, and by dumb it down i mean really, its not you , its me.
Next we will go thorugh the gamedev supplement to the reading, which is fairly basic, but again i will dumb it down.
So forgetting everything about programming, i am completely programming illiterate, carrying on with the maddness...

The hello world application

1. using System;
2. class Hello
3. {
4. static void Main() {
5. Console.WriteLine("Hello, World");
6. }
7. }


The most useless application ever created, but good to learn from.

BTW , we are using the most confusing documentation ever, im not sure, but i believed this is geared tword advanced users, so either they were thinking
"hey if they know how to program, than they should pick this language up fast", or "hey lets confuse the crap out of begineers to make them think this
language is amazing". The latter choice worked for me i guess.

http://download.microsoft.com/download/5/e/5/5e58be0a-b02b-41ac-a4a3-7a22286214ff/csharp%20language%20specification%20v1.2.doc


So now lets break it down to how i see fitting, a more logical explaination.
1. using System;
This line references the System namespace.
The semi colon ends a programming statement, It is like the period of sentances, used to declare, the first line is declaring that the system namespace will be used in the application.
Namespaces - Namespaces simply hold information. Two namespaces can have the same information. A good example of this is one i have reworked thats is found in chapter three...


namespace helloworld1
{
class hithere
{

static void Main() {
Console.WriteLine("Hello, World");
}

}

}

namespace helloworld2
{
class hithere
{
static void Main() {
Console.WriteLine("Hello, World");
}

}

}

As you can see the two namespaces above contain the same class and the same helloworld method as above. Don't think too much into it. I will do that for you.

Game programming example. Why you would use two different namespaces, with the same information.
Lets take any game with Swords in it. Swords are very similar to each other. They would have a size, maybe a sharpness, or even a weight.
These properties all apply to a sword so you might have a namespace for say the "Game - Zelda", and one for "game - Final Fantasy", each
containing a sword class, each containing the properties os size, sharpness, and weight.


Now lets take a look again at that line, using System; ,
This line references the System Namespace, which contains a bunch of stuff that is used in console applications, like this HelloWorld application uses,
if your wondering whats in it, i have no clue, but i am sure google does.

For this application we need to use the System namspace because it contains the Console class, translation: its got what we need to make the console write a line of text, etc.




2. class Hello

I have always been told that a class is like a blue print, so i am going to go on that pun.

A class is like a blue print, lets use swords again. Like mentioned above you have your class sword, that contains properties such as size, weight, and sharpness.
Never mind syntax for right now, or the attributes within the members.



class Sword
{
Size
{
small
medium
big
}

Weight
{
light
heavy
}

Sharpness

{
dull
sharp
}

}

When you think about it, the class sword, will at some point become an object when implemented, without the members, which are in this case, size, weight, and sharpness,
we would have the same type of sword being created, the attributes within the members define a unique object, or plain object.

why? lets assume sword is the base of all other swords

Lets use another example

You are trying to create the Master sword, The want the Master sword to inherit all of the attributes of the Sword class, but have new attributes, like an
attack power.

class Master Sword : Sword
{
Attack Power
{
10000000
}

}


Master Sword Inherits all of the attributs of sword , which are weight, sharpness, and size, and has another member called Attack power.

This is a rouge outline of inheritance, remember we are only focusing on understanding basic concepts, syntax is not a concern right now for examples.


3. "{}"

These are refered to are brackets. Brackets encase sections of code. You could say brackets represent the word contain.
An example of this in action is:


namespace helloworld1
{
class hithere
{

static void Main() {
Console.WriteLine("Hello, World");
}

}

}

The namespace helloworld1 contains a class hithere. The class hithere contains a Main() method(explained in next section). The Main() method contains a statment which writes "Hello,World" in
a console window.



4. static void Main()

This is the entry point of the program. All C# programs have one of four entry methods. A static method named main is always the entry point of a C# program.

static void Main() {...}
static int Main() {...}
static void Main(string[] a) {...}
static int Main(string[] args) {...}

void - specifys that the method does not return a value
int - specifys that the method returns a value of type int (an integer , a number, we will go throught types later)



5. Console.WriteLine("Hello, World");

This of a bowl of soup. Every line of code up until now is like the bowl, a place holder, and "Console.WriteLine("Hello, World");" is the soup.
The Console is reference from the System Namspace being used, and the method of WriteLine, is being called from the Console class, which writes the line of
"Hello World" in a Console window. You could put any text between the quotes, and the Console would Display that, lets take a name for example

1. using System;
2. class Hello
3. {
4. static void Main() {
5. Console.WriteLine("Bob Brinker");
6. }
7. }

Output: Bob Brinker



So thats enough for now. Going over some of the basic concept has been fun, and hopefully ,
the rest of the language specification will invoke as many questions and thoughts, and gear me tword a better programming experience




No comments: