C++ problem (redone)

Jason Gurtz jason at tommyk.com
Fri Aug 27 06:55:40 PDT 2004

On 8/27/2004 03:28, michael wrote:
> I hope this is better;[...]

mmmm, echo what Björn said

>   class car
>   {public:
>    int itsYear;
>    string itsName;
>    };

I see you want to save vertical space from.  Try this instead:

  class car {
      int itsYear;
      string itsName;

The main thing is to line up vertically the start and end of each
logical block.  e.g. The "c" in class with the ending curly brace.

When emailing code inline, yes sometimes the lines are long and would be
wrapped.  I would say a minimum of 2 spaces for all indents (as above)
and if it still doesn't fit at 72 chars then send as an attachment
instead.  I think most people would agree with me that 4 spaces is the
"normal" indentation level.

IMO, Another good practice is to initialize all variables to a known
value.  e.g.

  int itsYear     = 0;
  string itsName  = "";   // null string
  char someLetter = ' ';  // Note space char as the initializing char.
  float myPrecise = 0.0;

No, it's not necessary.  But, it does explicitly get rid of any garbage
value that may exist in that location and for me (as a C++ beginner) it
improves the readability as well.


~Jason  (who is looking forward to intermediate C++ this fall :)


More information about the lfs-chat mailing list