Re: Some Advice.

From: Robert W Hand (rwhand_at_NOSPAMoperamail.com)
Date: 02/13/04


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


Relevant Pages

  • Re: Some Advice.
    ... > int main{ ... Yes I am learning that and and implementing as I go along. ... you should provide inclusion guards for headers. ... > function definitions into separate source files. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: First C++ Project
    ... Neither of these two headers are part of standard C++. ... int main ... > draw line; ... it declares. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: How to calculate number of files on a disk
    ... But I'd like to also get the number of files on a disk as well. ... case I'm getting close to maxfiles, or incase the number of files ... int main { ... allocate that many headers for new files. ...
    (comp.os.vms)
  • [PATCH 6/11] eCryptfs: Update metadata read/write functions
    ... without having to go through the eCryptfs getxattr. ... goto out; ... static int ... Write the file headers out. ...
    (Linux-Kernel)
  • Re: [was] addition to ipfw (read vlans from bridge)..
    ... e.g. vlan headers and ethernet headers. ... However, I have one question regarding "etype", please see below. ... struct tcphdr *tcp; ... int flags; ...
    (freebsd-net)