CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2010
    Posts
    2

    Smile Where am I with C++

    Hi There,

    I've been programming in c++ for a few months and I was wondering if you could look at my project(A Text Based Game) to tell me where I am with it and if there is anything I could work on. Could you just glance over the code in all 3 files because you can't see the complexity of the application from the unfinished compiled main executable.

    Thanks

    XtremeDeveloper

    http://dl.dropbox.com/u/9199238/IRPG.zip

  2. #2
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Where am I with C++

    Your website is actually blocked to me. Why don't you just paste the code here? It will make it that much simpler for everyone. There is no post size limit.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  3. #3
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: Where am I with C++

    Hi,

    only a few things seen after a very short review:

    1. Your code is terribly formatted.
    Code:
    int MaxLevel=myCharacter.Level+5;
    Is there any reason not to write
    Code:
    int MaxLevel = myCharacter.Level + 5;
    Do you see the difference? The meaning of this source line can be "scanned" much better (there is one int variable declared and initialized by the sum of 5 and the level of myCharacter).

    2. You make use of many "magical" constants.

    "5" "250" : No one knows what they are.

    A better style is to make them as constants:
    Code:
    #define MAX_POINTS_PER_ATTACK 125
    If you use these symbolic constants your code will be readable much more.

    3. Your program is not error prone.

    Try to input "a" in the "main menu" ....

    4. You mixed the extensions of .h and .cpp files.

    Your character.cpp contains what usually can be found in a header file.

    So far for the moment

    With regards
    Programartist

  4. #4
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Where am I with C++

    My preference is to use consts instead of define wherever possible due to #define's complete lack of scoping.

    Code:
    const int MAX_POINTS_PER_ATTACK = 125;
    Spaces are good.
    To quote someone (who I can't recall)

    Programs must be written for people to read, and only incidentally for machines to execute.

    or

    Any fool can write code that a computer can understand.
    Good programmers write code that humans can understand.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  5. #5
    Join Date
    Dec 2010
    Posts
    2

    Re: Where am I with C++

    Thanks for your comments and pointers.

    I was really looking for where I'm at with c++ at the moment.

  6. #6
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Where am I with C++

    Quote Originally Posted by JohnW@Wessex's Avatar
    JohnW@Wessex
    To quote someone (who I can't recall)

    Programs must be written for people to read, and only incidentally for machines to execute.
    Not bad. You may have forgotten the authors, but you quoted the preface to the first edition of Abelson and Sussman's Structure and Interpretation of Computer Programs word for word
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  7. #7
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Where am I with C++

    Actually I have several of those type of quotes pinned on the partition above my desk.

    Programs must be written for people to read, and only incidentally for machines to execute.

    Any fool can write code that a computer can understand.
    Good programmers write code that humans can understand.


    ‘Saving on typing’ is not a valid reason for implementing something in a particular manner.


    Correct is better than fast.

    Simple is better than complex.

    Clear is better than cute.

    Safe is better than insecure.


    There are two ways of constructing a software design; one way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies.

    The first method is far more difficult.

    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  8. #8
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Where am I with C++

    These quotes are not only good for a laugh, but they are actual advice you can (should) adhere to. I don't think I'm the best programmer, but I always try my best, and strive to write the best I can. Its these kind of sentences that fuel me.

    Also, here are a ton of them: http://www.quotegarden.com/programming.html
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  9. #9
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Where am I with C++

    A big problem that I see though, is that what's easily read for you, may not be easily read for me. Most C++ developers I know stay away from mem* or *alloc like the plague, but as a former C and assembly developer, I use them fairly extensively for primitives.

    A former java programmer may be completely confused by virtual functions and calling them, so will find other ways around them which are easy to read to him, but not us.

    I knew a former Visual Basic programmer at my old company. We had to work on a project together once, and we had a really hard time reading each other's code.


    I prefer better documentation to better-written code. Then again, I used to do a lot of things that required real-time speed or embedded memory constraints. That's why I love tools like Doxygen, and when libraries have huge documentation files.
    Last edited by ninja9578; December 8th, 2010 at 04:20 PM.

  10. #10
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Where am I with C++

    We use both Doxygen and a coding standards document.

    , and we had a really hard time reading each other's code.
    We've had the problem in the past where individual coding styles have led to confusing and inconsistent code. Having a common style guide really helps when modifying another's code. We had one guy work here who wasn't even self consistent!
    He used all of the common styles, changing tack at random times

    e.g.
    My_Function()
    MyFunction()
    myFunction()
    my_function()

    + incomprehensible function and variables names..

    Grrr, don't get me started!
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  11. #11
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Where am I with C++

    Wow, that's pretty crazy. At least people I have trouble coding with are consistent.

    Would I be considered inconsistent? I use camel case in C++ (myFunction) and underscores when writing C (my_function.) I think that's fairly common though, right?

  12. #12
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Where am I with C++

    Mind you, even if you stick to a common convention you can end up with a mixed bag of styles.

    As a company we decided on My_Function()
    Calling anything in MFC gives MyFunction()
    If it's in the STL then you get my_function()

    All you can really do is limit the number of variations that are under your control.

    At least people I have trouble coding with are consistent.
    Is it because you are all using different coding styles (brace positions, case, underscores etc.) or is it more fundamental?
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  13. #13
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Where am I with C++

    Overall design too. He was a VB programmer, VB has no braces, it's only partially object oriented an no one uses it that way, so it was more like C with objects than C++.

    Braces don't bother me, I can read those fairly easily.

Tags for this Thread

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