Re: Some Advice.
From: Joec (joec_at_annuna.com)
Date: 02/13/04
- Next message: Joec: "Re: Some Advice."
- Previous message: Joec: "Re: Some Advice."
- In reply to: Robert W Hand: "Re: Some Advice."
- Next in thread: Robert W Hand: "Re: Some Advice."
- Reply: Robert W Hand: "Re: Some Advice."
- Reply: Mike Wahler: "Re: Some Advice."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 13 Feb 2004 22:25:49 GMT
Robert W Hand wrote:
> 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.
>
Yes I am learning that and and implementing as I go along.
> 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;
> };
>
Not fimilliar with that will have to read up on it.
> #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).
Yes that is true. I I am afraid to go back and change a bunch of name.
>
> 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.
OK, I didn't know that. I saw that in an example somwhere. But it may
have been a different situacion. I have not seen amy large scale code
and I have been making it up as I go along.
>
> 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.
True, but I am using several files and I was planning to copy them over
later. It is that the source is linked and I already had 3-4 windows
open working on a single problem.
>
> Seventh, you should only have one main() function. It seems that
> Idemo.cpp and Game.cpp both have one defined.
Idemp is another porgram that got stuck in the folder when I archived
it. I plan to remove it.
>
> 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.
Didn't think I did that.
>
> HTH.
Wow thanks for the tips. Some of them I am learning as I go along. I
am learning that naming is far more important in C than in Perl.
Writing a program and learning is very fustrating. I want to learn. I
can read books on syntax and theory all day but it doesn't matter until
it is applied.
- Next message: Joec: "Re: Some Advice."
- Previous message: Joec: "Re: Some Advice."
- In reply to: Robert W Hand: "Re: Some Advice."
- Next in thread: Robert W Hand: "Re: Some Advice."
- Reply: Robert W Hand: "Re: Some Advice."
- Reply: Mike Wahler: "Re: Some Advice."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|