XNA Creators Club Online
Page 1 of 1 (9 items)
Sort Posts: Previous Next

Programming analogies and questions

Last post 7/25/2008 1:50 AM by Lachdahnan. 8 replies.
  • 7/24/2008 8:07 PM

    Programming analogies and questions

    This is my 3rd or 4th time attempting to learn a programming language over the years. It seems every time I get very frustrated because I have a hard time moving ahead if I don't fully understand how something works. I don't know why, but it causes me a lot of confusion. I managed to get moderately far in C++ quite a few years ago, but I ended up in frustration again :P

    Anyway, I refuse to give up and want to take a stab at C#. This time I am going to try to take things slower and try to understand what the heck I am looking at, and how it works in the big picture the best I can. At the moment I am working my way through the 2D tutorial and have grabbed some code samples that I would like to have examined further.

    using System;

    using System.Collections.Generic;

    using Microsoft.Xna.Framework;         (  etc. etc.  I consider these to be my toolboxes. Inside my toolboxes are the tools (classes) that I will be using. Some tools have more than one function, and sometimes another tool attached to them and so on. )

     

     

    namespace Tutorial_Project_1      (I suppose I would call this the foundation of the game where everything is started on )

     

     

    public class Game1 : Microsoft.Xna.Framework.Game      (creating a "non-encapsulated?" class called Game1? )   (Then the   ": Microsoft.Xna.Framework.Game" Im not sure what the colon is doing to the 'Game' object here.)    Not sure what analogy would be used here.. the framework of the building?

     

    That is all I have for the moment. Any advise or suggestions on what I should change for my analogies is welcome. Thanks!

  • 7/24/2008 8:29 PM In reply to

    Re: Programming analogies and questions

    Think about classes as your tools. So the Game class has a set of properties and actions useful for making a game.

    Think of the namespaces as a kind of path, or address becuase you can make a Game class and so can I so how do we tell them apart?

    e.g. Zman.Samples.Game and Lachdahnan.Aliens.Game are really 2 different classes.

    then using statements are shortcuts so that you don't have to type in the full namespace each time.

    e.g. if you have:
       using a.b;
       using e.f.g;
    and you type in
       Game g = new Game();
    Then the compiler looks for a.b.Game and e.f.Game to find the full name.

    Hope that helps

    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 7/24/2008 8:30 PM In reply to

    Re: Programming analogies and questions

    The only thing I can add at the minute is this: 

    public class Game1 : Microsoft.Xna.Framework.Game      (creating a "non-encapsulated?" class called Game1? )   (Then the   ": Microsoft.Xna.Framework.Game" Im not sure what the colon is doing to the 'Game' object here.)    Not sure what analogy would be used here.. the framework of the building?

    The best analogy would probably be that the Microsoft.Xna.Framework.Game class referred to is the foundations of the building. The Game1 class the pipework that goes through it.

    What you have here is an inheritance. Game1 has all the properties and classes of Microsoft.Xna.Framework.Game, plus anything else you want to add to it.

    This line simply means that you are creating a class called Game1 that has all the bits of the inherited class Game. The colon simply denotes this.

  • 7/24/2008 9:02 PM In reply to

    Re: Programming analogies and questions

    The : in this case means "inherits from." In this case, it means that your new class, called "Game1," inherits from the Microsoft Game class. Inheriting means that it has all the public properties, methods and other members of the base class you inherit from. You can then go ahead and add more functionality, or override functionality from the base class.

    Think of classes as blueprints of tools -- when you create instances of objects (using "new") then you get the actual tool that can actually do something. Think of deriving (inheriting) as creating a new blueprint that says "I'm the same as this other guy, but adding the following things..."

     


    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 7/24/2008 10:38 PM In reply to

    Re: Programming analogies and questions

    My brain hurts  :(   hehe I think I understand what you all are saying. I appreciate the input. Its just so overwhelming feeling sometimes. I really want to get this though so Im gonna keep at it! Thanks again!
  • 7/24/2008 11:54 PM In reply to

    Re: Programming analogies and questions

    I understand how these analogies help when learning a new concept but be wary of them. Use them as a crutch to get you going but don't get too attached to them, sooner or later you will have to 'kick away' the crutches because the analogies start to break down. This may leave you in the same 'stuck' position when you try to grasp other related concepts that do not fit into the current analogy very well.

    For example, the final bit of code (the declaration of a class) is in some ways like the foundation of a building but when you start talking about methods and properties of a class, there's no elegant way to fit it into the building analogy. It starts to get more and more contrived.

    There are loads of things in programming that aren't well represented by a real-world analogy so sometimes you have to just call a 'class' a 'class'.

    I hope this makes sense and isn't seen as an overly-critical view of what you are trying to do, just some advice on how it can also confuse.

  • 7/25/2008 12:19 AM In reply to

    Re: Programming analogies and questions

    The best thing to do is write a simple c# console application and explore these things in it. For example, make a class and name it how you want.

    Then create an instance of that class in your program. Create two, then three just to see how your class definition is just a description of the class that is used to create them when your program runs. Better to work slowly and methodically by playing around with things rather than trying to make sense of everything before you start really learning.

    You could maybe write a class called Animal and give it a "Walk" method that just prints out "Walking..." when called. Create couple of hundred Animals and then call each of their "Walk" methods to see them print out "Walking..."

    If you can't do that, don't worry but just keep going over it until it clicks. The XNA blank new game project is more complex than this so it might seem less daunting.

    BTW, inheritance in this case would mean you could create a Cat class and a Dog class and make them both inherit from the Animal class. Both the Dog and Cat class would then come with the Walk method built in, allowing you to re-use existing functionality already in the Animal class.

  • 7/25/2008 12:48 AM In reply to

    Re: Programming analogies and questions

    From what I have seen in the past, I can understand what your getting at about the "crutch" until later on. I think I will continue to use the crutch because my brain seems to be very reliant on images to help me understand things like this. Math and such things has always been a weakness of mine :P

    Thats ok though. I will try to adapt slowly as the changes come and just take it in as I go. So maybe I will crawl, walk, then run, then slow down to a fast walk and back to running again :) Or maybe I'll trip and fall while running and fall face down... but then I find a dollar on the ground! Hmmm I guess thats my queue to get back to work...

    I will attempt to make myself a basic outline of what is going on, a hierarchy crutch perhaps :D Ill post it on here if I do that.

  • 7/25/2008 1:50 AM In reply to

    Re: Programming analogies and questions

    Okay, I made a quick little reference for myself. But before I use it, could somebody tell me if its on the right track please? :P

    I threw it on imagedump so heres the link:

    http://www.imagedump.com/index.cgi?pick=get&tp=536180

Page 1 of 1 (9 items) Previous Next