CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2009
    Posts
    15

    Need a Little Guidance

    I'm new to C# and programming and I could use a little guidance.

    I started off reading Sam's Teach Yourself the C# Language in 21 Days and now I am working through Visual C# 2008 Step by Step.

    I seem to be hitting a wall, though. I think I am grasping the concepts, but I'm not seeing how to put it all together.

    Maybe some advice on how other people go through designing and writing programs would help? I might just be getting lost in the details or missing something obvious or just need a different view than the one I have at the moment or maybe I am just feeling a bit overwhelmed being so new to it, I'm not sure. I also probably have a tendency to make things overly complicated.

    So what steps do you go through when designing you programs? Especially when it comes to the details of what you start with when writing the code and how you expand on that and the layout of the code itself. I'm not sure if layout is the right word for what I mean and I'm not sure how to explain that better either.

    Any advice is appreciated.

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Need a Little Guidance

    I would avoid any book that claims to teach you how to program in 'X' number of days. It is just not possible. Becoming a proficient software developer takes years, not 21 days. The best way to learn is by doing. Just write a lot of code. When you encounter an issue, you can always ask questions here or ask our good friend Mr. Google. Just be patient and keep developing your skills. once you are familiar enough with the syntax and semantics of the language (a good test of this is when your biggest problem is not keeping the compiler happy, but bugs in your code), then I would suggest looking into design patterns (Head First Design Patterns is a good book). It really does just take time and effort.

  3. #3
    Join Date
    Mar 2009
    Posts
    15

    Re: Need a Little Guidance

    Oh, I'm not expecting to become proficient overnight. The books are just what I used to introduce me to C# and to get me used to the terminology and the basics of how it works. What they don't seem to go into is putting it all together.

    I'm not sure how to explain it better. It's like when you write a story... you start off with the general idea, then you think it through to figure out how the story develops and what happens in more detail. Then you figure out where it begins and you put pen to paper and begin writing. My problem would be putting pen to paper. That part just hasn't clicked yet for me.

    I'm trying to start off small, but I guess maybe I am not starting off small enough.

  4. #4
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Need a Little Guidance

    first i congratulate you because you are in a good first step.
    and don't expect after reading one book you should do everything just continue reading and practicing more.
    everyone start from the very first steps.

    i have gone this way:

    reading book after book (about 10 books till now for C#).
    some concepts have been repeated in the many books i have red. but i red them again and again to have them always in my mind.
    i get familiar with some concepts in only some special books (that's why i read more than one book).

    i bog down with some concepts in one book but i understood it by reading another book (that is another reason i read more that one book)

    for those concepts that are hard for me i break them to simpler concepts and sovle them one by one (i get help from google and articles focused on each concept).

    when i bog down on something i don't stop to solve it i continue reading beacuse of two reasnons:

    1- by reading the next steps you may understand privious steps
    2- always i have time to think about concepts that i have not understood already so it would be better to continue learning new things.

    i write code that are in the books (those that seams complicate to me) and playing with them and debugging them to understand them.

    i pay attention to algorithms and read books that explain desiging algorithms either with pesudo code or c++ or c# then try to implement them in my target language.

    i read math (everyday) because it helps me to fresh my brain and use math skills in my programs.

    try to understand Object Orinetd very good and apply it to your program. always imagine that OOP is something very similar to real life and relationships that exists in our life and enviroment.

    be active in forums.

    if you don't understand something don't worry just it several times from several sources and ask other people to help you.

    it is not needed that you memorize everything. i look like this: if i can do one thing for the first time so i can do it easier other times so it is not very esebtial to memorize it because after doing it more times automatically it will carved in my brain.

    a rule: try to memorize obvious, basic and most used topic in your brain and try to understand more hard topics and how to refer to them later.

    don't exhaust yourself on learing things; try to enjoy it. you are not forced to make nervous yourself.

    when you don't understand one topic be happy...lol...because you are reading advance topic and others even may have not heared about it.
    Last edited by toraj58; March 4th, 2009 at 05:13 PM.
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  5. #5
    Join Date
    Apr 2006
    Posts
    220

    Re: Need a Little Guidance

    Quote Originally Posted by BigEd781 View Post
    I would avoid any book that claims to teach you how to program in 'X' number of days. It is just not possible. Becoming a proficient software developer takes years, not 21 days. The best way to learn is by doing. Just write a lot of code. When you encounter an issue, you can always ask questions here or ask our good friend Mr. Google. Just be patient and keep developing your skills. once you are familiar enough with the syntax and semantics of the language (a good test of this is when your biggest problem is not keeping the compiler happy, but bugs in your code), then I would suggest looking into design patterns (Head First Design Patterns is a good book). It really does just take time and effort.
    Design Patterns are not for beginners. It will confuse him more. Unless he becomes good in algorithms, concept of functions/methods and object oriented programming, design patterns are of no use.

  6. #6
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Need a Little Guidance

    agree. we should not tempt beginners to start Design Patterns even as the second step.
    because that will frighten beginners and they wont be rewarded when they are messing with such complicated codes.
    i think for starting designing patterns atleast 3 years of nonstop programming is prerequiste.
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  7. #7
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Need a Little Guidance

    Yeah, I really meant that the OP should look at stuff like that after they have a firm grasp on the language and object oriented design. I don't know about three years though, I picked up design patterns after about a year of programming ( a lot of programming in that year though).

  8. #8
    Join Date
    Mar 2009
    Posts
    15

    Re: Need a Little Guidance

    Thanks guys.

    Don't worry, I ran across something about design patterns when I was still trying to decide on what books to get and I know that they are way out of my league.

    toraj, that sounds pretty much like what my plan is. Read what I can and practice the concepts as much as I can. Don't scare me about the math... I've been out of school for around 15 years and while I was a good math student, I have forgotten most of it. I have a lot of time on my hands at the moment which is why I thought it would be a good opportunity for me to start learning this.

    So far I decided to take what I think is a small simple program and and making it even smaller and simpler and then I plan on building it up to do what I actually want it to do. We'll see how that goes. I got a decent start on that last night.

    One other thing. I am worried about is picking up bad habits. Once something becomes a habit it's hard to change it. Any advice as far as what you think a beginner should be aware of to avoid bad habits?

  9. #9
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Need a Little Guidance

    the bad habit that most of people have is want to gain everything easiliy and as soon as possible but they forget that if we gain something easiliy - so okay - but everyone
    else can gain it as easiliy as us.

    if we want to be the distinguished people in the society we should go the hard way - still ok - some poeple start steping in the hard way but while encountering tall wall they stop
    and don't continue.
    the difference of those that reach the goal is when they face the wall they don't stop and passing it somehow: climbing it, breaking it, digging ground under it or just detour.
    some of us plan for something and count to reach the goal take us 10 years....then we say wow; - 10 years - forget it. after passing 10 years we see that we have not done anything.
    and others that have gone that way are 10 years in front of us.
    so till when we should think about what we should be or what shoud we do.
    we just need to start and solving the problem of each step in that step without worring about next step.
    good things in this universe are hard to get.

    sometimes we feel exhausted and think what am i doning/ where i am....that feeling is part of us. we can be something and we are one (not two one).
    so when we do something it would be better that we do our best.
    in a race filed each runner can run with its speed. so that's enough for us to run with our speed because we can not run with others speed.
    all runners are winner because soon or later they reach the end line.
    Last edited by toraj58; March 6th, 2009 at 11:54 AM.
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  10. #10
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Need a Little Guidance

    Quote Originally Posted by Vorkosigan View Post
    Thanks guys.
    toraj, that sounds pretty much like what my plan is. Read what I can and practice the concepts as much as I can.
    reading and practice and reading and practice is one of the surest way IMHO.

    There will be always people with more experience who did something you are doing maybe quicker and better, but thats no problem.
    If read a code which ooks easier and better then mine I'm going to test it, using the debugger to see how it works.

    The debugger. This is a very necessary point in a learning curve, you will see. Never be afraid of bugs or crashes as long as you are looking to debug them and learning why they occure.
    This brings you up to a point where you have experience.Experience is built of lots of faults and solved errors. When you do an example of a code in a book two necessary steps, often forgotten are
    a) Always type the code yourself, you will get a better understanding of it during typing line by line
    b) Always run it with the debugger so you can see what it is doing
    So far I decided to take what I think is a small simple program and and making it even smaller and simpler and then I plan on building it up to do what I actually want it to do. We'll see how that goes. I got a decent start on that last night.
    If you have an idea to do a program break it into easier and smaller logical steps, because sometimes it seems complicated to get the full idea into the mind but if you break bigger steps into smaller ones you will succeed.
    One other thing. I am worried about is picking up bad habits. Once something becomes a habit it's hard to change it. Any advice as far as what you think a beginner should be aware of to avoid bad habits?
    One of the badest habits lots of us have IMHO is to less of adinistration to less lines of documentation to any code we wrote I find myself also looking in this mirror.

    I dont know but as long as you are always willing to learn and looking to get better and better I think bad habits may come and go, to be honest I dont know a good conceipt against this, because if we can see that something has become a bad habit, we wouldn't do it anymore, right ? But reading different books to the same theme is always a point not to copy others bad habits.

    At least I would invite you to read my article series about dockable panels. Its a beginners series and it explains how to do something like that with lots of pictures. And it also shows you a bit how to go on from an idea to reality. And its done in an easy to understand way. The links are in the bottom of my post. each article also contains a zip file with the full code so you can compare what you do during readin the article with the product always, which makes it easier to find errors.

    In between more then a year has past since I did this series and I have tested the code in different of my applications. Per sure in between I would do a lot of it in a totally other, more experienced way, but its still a good beginners tutorial IMHO.
    And its not finished, because now after a year of using and testing I think part 8 will follow in the end of this or the early next month
    Last edited by JonnyPoet; March 9th, 2009 at 03:06 PM.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  11. #11
    Join Date
    Jun 2008
    Posts
    154

    Re: Need a Little Guidance

    My biggest hurdle was knowing how the interpreter reads the code, and often I got confused as to why a reference was not being changed - or why I couldn't change something in a class etc...

    here is a little example of some very basic stuff that took me forever to figure out why it was or wasn't working

    Code:
    namespace Mathematics
    {
        public class Modifcator
        {
            public decimal nextValue;
            public void ChangeUpSomeValues(decimal value, int numberValue, decimal classtype)
            {
            int newValue = Convert.ToInt32(value);  //converting a decimal to int
            newValue = newValue + numberValue;
            nextValue = newValue * classtype;
            }
        }
    }
    Now this class is going to be using Modificator's function, like so

    Code:
    namespace Mathematics
    {
        public class PutInSomeNumbers
        {
        ///1st I need to instantiate it
        Modifcator maxnewnumbers = new Modificator();
    
        ///here a bunch of variables I am going to modify
        public decimal Jargon = 5m;
        public int ANumber = 3;
        public decimal ChangeIt = 0.73m;
        public decimal AResult;
    
        ///now we use the function like so - plugging in out variables like legos :)
        public PutInSomeNumbers
            {
            maxnewnumbers.ChangeUpSomeValues(Jargon, ANumber, ChangeIt);
    
            AResult = maxnewnumbers.nextValue;
            }
        }
    }
    it was quite some time of just writing code from examples and reading tutorials before I could comfortably write my own classes and using functions.
    Last edited by bixel; March 9th, 2009 at 03:04 PM.

  12. #12
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Need a Little Guidance

    As you spoke about 'bad habits' so I'll do some moddifications to your code to teach you a bit of how doing better. OK ? ( Changes are done in red )

    Code:
    namespace Mathematics{
     
        public class Modifcator   {
            //public decimal nextValue; -> always encapsulate it ALWAYS
            // not encapsulate it is really a BAD habit
            private decimal nextValue = 0; // a good habit is to initialize your fields
            #region Constructors( Ctors)
            public Modificator(){
                decimal nextValue = 0; // some people initialize their fields in the Ctor
             }
            // an additional Contructor if you need to initialize this value 
            public Modificator(decimal nextVal){
                 nextValue = nextVal;
            }
            #endregion
            public void ChangeUpSomeValues(decimal value, int numberValue, decimal classtype)  {
            int newValue = Convert.ToInt32(value);  //converting a decimal to int
           
              // newValue = newValue + numberValue;-> look
              newValue +=numberValue
              nextValue = newValue * classtype;
            }
            // now we create a property to get access to your value        public decimal NextValue{
                  get{ return nextValue;}
                  // if you also need to set it at runtime
                  // if you dont need to set this value or you set this value at creation time then you dont need this.
                  set { nextValue = value;}
            }        
        }
    }
    Now this class is going to be using Modificator's function, like so

    Code:
    namespace Mathematics
    {
        public class PutInSomeNumbers
        {
        ///1st I need to instantiate it
        // note(hint): Kamelnotation would it make much easier to be read
        private Modifcator maxNewNumbers = new Modificator();
     
        ///here a bunch of variables I am going to modify
        private decimal jargon = 5m;
        private int aNumber = 3;
        private decimal changeIt = 0.73m;
        private decimal aResult;
        // note for getting access to this fields(values ) from outside this class create properties as shown above
     
     
        ///now we use the function like so - plugging in out variables like legos :)
        // note: The following is no method as it has the class name and no outparaeter, its a Constructor !
      // hint: its not very useful to have a method which calcultes predefined values All instances of this class will have the same result for aResult, so why this should be calculated. (But IMHO this was only an example )
            public PutInSomeNumbers  {
            maxNewNumbers.ChangeUpSomeValues(jargon, aNumber, changeIt);
            // Here we give the result to the property not to the Private value ( I'll explain a bit later why )
            AResult = maxnewnumbers.NextValue; // we are accessing the property now
            }
             
            public decimal AResult{
                get{ return aResult;}
                set { aResult = value;}
            }
        }
    }
    This could be expanded for a lot of more examples if you need.
    For example if you need to be informed when your AResult Value is changed you can do the following
    Code:
    //You add a private delegate 
    private event EventHandler aResultChanged;
     
    //and you create the Public event
    public event EventHandler AResultChanged{
         add { aResultChanged += value;}
         remove { aResultChanged -= value;}
    }
     
     //now we need a method to fire this event
    private void OnAResultChanged(){
       // we make sure it only fires if any delegate is connected to our event
       if ( aResultChanged != null){ 
           aResultChanged(this, new EventArgs()); // The EventHandler delegate has the pattern ( object sender, EventArgs e) as you per sure have already seen
       }
       
       // and to get this called we change our  property a bit
            public decimal AResult{
                get{ return aResult;}
                set { if (aResult != value){
                            aResult = value;
                            OnAResultChanged(); // fires the event
                          }
                      }
            }
    }
    Any now you will understand why I have done the return value of your method to the property as this will fire the Change event. If you want to change values internal without informing others then you simple give the output to the private value. In that case only changes coming from outside the class will be notified by our event.

    This is a good example why we use classes and properties and why its necessary to encapsulate the values.
    Last edited by JonnyPoet; March 10th, 2009 at 03:32 AM.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  13. #13
    Join Date
    Jun 2008
    Posts
    154

    Re: Need a Little Guidance

    Awesome! Yeh not protecting you variables as private is a pretty bad habit. I used to be so confused about the Constructor thing.

    #region Constructors( Ctors)
    #endregion

    what is Constructor-ish about that? Is that even needed to be labeled as Constructor at all? I use #region #endregion to mark fields of code and to keep things clean. But that doesn't really do anything. And I wanted to point this out cause a lot of new coders see and do by an example and they will think every class will need a

    #region Constructors( Ctors)
    #endregion

    I didn't use a Constructor for Modificator simply because I didn't want to pass any arguments when creating a new class. He used #region #endregion to break up his code into nice chunks and to introduce something that should be used.

    Here is an example of a Constructor (and a Constructor is not a special sys class or function, I used to think it was :P).

    Code:
    public class Square
    {
          public Square (x, y)  //<<< Constructor
          {
    I now have a Constructor of the class Square, and it can take arguments so when I create a new Square class I can directly tell it what size its going to be.

    Square myNewSquare = new Square (18, 20);

    I had to write about this cause the whole thing of Constructors confused me greatly. I was working on some game code modifying a popular game (like UT3) and I used to think all the time, how does this code compile? Where are the Constructors?? hahah

  14. #14
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Need a Little Guidance

    Quote Originally Posted by bixel View Post
    Awesome! Yeh not protecting you variables as private is a pretty bad habit. I used to be so confused about the Constructor thing.

    #region Constructors( Ctors)
    #endregion
    Simple said #region and 'endregion is only there to break code into little nice chunks. It does nothing else Think to a big class with more then 1000 lines of code then its bad always to look for anything in the whole thing. If you have regions you can close and open them by clicking on them - try it you will see it works- And so you only open that regions of your code where you just are working. Such simple

    In the example I did this because it is a good habit to do that. And as you see I did two constructors so you can construct your class with and without a startvalue.

    what is Constructor-ish about that? Is that even needed to be labeled as Constructor at all? I use #region #endregion to mark fields of code and to keep things clean. But that doesn't really do anything.
    Exactly.

    ...And I wanted to point this out cause a lot of new coders see and do by an example and they will think every class will need a

    #region Constructors( Ctors)
    #endregion
    Yea in my eyes it should be part of each good C# book how to get order into your code. Its mostly missing there So I did it here as an example for good habits. Yep, you got it.
    I had to write about this cause the whole thing of Constructors confused me greatly. I was working on some game code modifying a popular game (like UT3) and I used to think all the time, how does this code compile? Where are the Constructors?? hahah
    If you dont define any constructor the compiler itself creates an empty one
    Code:
    public class Example{
         // public Example(){} // if you dont have more then one you dont need to write this explicitly, its done by the compiler.
     
        ----
     
    }
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

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

Featured