Re: Some Advice.
From: Robert W Hand (rwhand_at_NOSPAMoperamail.com)
Date: 02/13/04
- Next message: Patio87: "Bloodshed C++ IDE compiler dos shell problem"
- Previous message: Robert W Hand: "Re: Further along the evaluation order: Was: Order of evaluation."
- In reply to: Joec: "Some Advice."
- Next in thread: Mike Wahler: "Re: Some Advice."
- Reply: Mike Wahler: "Re: Some Advice."
- Reply: jeffc: "Re: Some Advice."
- Reply: Joec: "Re: Some Advice."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 12 Feb 2004 23:24:31 -0500
On Fri, 13 Feb 2004 02:45:51 GMT, Joec <joec@annuna.com> wrote:
>This mess of a program is posted at my site:
>www.annuna.com/perl5
I did glance at a few of your files. There are a few problems that
are glaring.
You need to indent your code. Code like this will put anyone to
sleep.
int main(){
char in;
string n;
cout<<"Welcome to my game...\n \n";
cout<<"What is your name?";
cin>>n;
Next, you should use identifiers that are "self-documenting". In
particular, I would avoid identifiers like n in a main function. I
must admit that I use single letter identifiers in very limited
scopes, but in larger scopes, it is easy to lose track of its meaning.
name or PlayersName would have been better choices.
Third, you should provide inclusion guards for headers.
#ifndef H_BASE
define H_BASE
struct cord{
int x;
int y;
};
struct drs{
int ud;
int lr;
};
#endif
Fourth, you need comments. I assume that cord is coordinate (note
misspelling makes me somewhat uncertain), but what is drs? You should
not make your identifiers a guessing game for a future maintainer
(including yourself).
Fifth, I would be careful about including other headers in your
headers. It may be the best way to handle something, but it can lead
to thoughtless errors, too. I usually try to do the including in the
cpp file. Your game.hpp seems to have been put together by rote
rather than by thinking.
Sixth, I usually keep one source and header for each C++ class. And I
try to pick names that suggest the class or its function. You seem to
put several classes together in the same header. Again, it may be the
best way to handle something, but it may not be the best way to handle
every situation. In large programs, it is easy to lose a class if it
is hidden among many files.
Seventh, you should only have one main() function. It seems that
Idemo.cpp and Game.cpp both have one defined.
Eighth, you should separate class definitions from other non-dependent
function definitions into separate source files. You have class
definitions and main() defined in the same source file. Again, for a
short program, that might be fine. But try to find main in a very
large program with many files.
HTH.
-- Best wishes, Bob
- Next message: Patio87: "Bloodshed C++ IDE compiler dos shell problem"
- Previous message: Robert W Hand: "Re: Further along the evaluation order: Was: Order of evaluation."
- In reply to: Joec: "Some Advice."
- Next in thread: Mike Wahler: "Re: Some Advice."
- Reply: Mike Wahler: "Re: Some Advice."
- Reply: jeffc: "Re: Some Advice."
- Reply: Joec: "Re: Some Advice."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|