Re: Nasty code...but please critique it anyway :-)

From: J. Campbell (mango_maniac_at_yahoo.com)
Date: 11/07/03


Date: 7 Nov 2003 06:53:21 -0800

Martijn Lievaart <m@rtij.nl.removefromhere.invalid> wrote in message news:<pan.2003.11.07.09.30.22.246973@rtij.nl.removefromhere.invalid>...
> On Thu, 06 Nov 2003 12:51:57 -0800, J. Campbell wrote:
>
> > Jerry Coffin <jcoffin@taeus.com> wrote in message news:<MPG.1a140b966bc2ca26989bd6@news.clspco.adelphia.net>...
> >> In article <b97c86e1.0311041217.2aeb32b7@posting.google.com>,
> >> mango_maniac@yahoo.com says...
> >>
> >> [ ... ]
> >>
> >> > I must be pretty dense...I had the hardest time understanding what I
> >> > was doing wrong. I think I get it now. Will you take a look at the
> >> > (revised) code from my first link in this thread and tell me if my use
> >> > of headers is now more or less normal?
> >>
> >> If I still had the link handy I would, but I don't...
> >
> > http://home.bellsouth.net/p/PWP-brightwave
> >
> > Sorry I didn't include the link before...I didn't want people to think
> > that I was entheusiastically pimping my novice code, and the link was
> > just up the thread, at least on my newsreader ;-) Anyway, thanks for
> > responding.
>

> unencrypt.h:15: `Filespec' was not declared in this scope
>
> (snip a lot more errors due to missing headers)
>
> make: *** [J_Crypt.o] Error 1
>
> Compilation exited abnormally with code 2 at Fri Nov 7 10:18:11
>
> It really is better to watch your case. :-)

Martijn, thanks for the reply.

Sorry about the case errors with compilation...It's a hard error to
catch when there is no (local) penalty for making it (on my DOS
machine).

>
> A quick look on some random chosen files.
>
> - hashSclass.h
> You only need <string>, move all the other #includes to the C++ files.
>

Is this a style issue? I moved all #includes to the header because I
read in a different thread (while trying to understand appropriate use
of headers), "put everything that will be needed for the class in it's
header", which makes some sense. Is there a reason to put the
#includes in the *.cpp file? I'm not arguing a point, just trying to
learn ;-)

> - J_Crypt.h
> A file that includes all other headers. A style issue, but I don't like
> it. Also, including <iostream> may lead to code bloat and longer
> compilation times. Include it only where needed.

Any pointers to where I can learn about using <iosfwd> instead of
<iostream>?

Can you demonstrate how to use <iosfwd> rather than <iostream> to
avoid code bloat in the following, trivial example?

#include <iostream>
using namespace std;
int main(){
  cout << "Thanks Martijn!" << endl;
  return 0;
}

>
> - Encrypt.cpp
> Looks good. Good comments, very readable. Only thing is that you do user
> interaction here. Better to decouple this. A way to do that would be to
> pass a const ostream& or a function pointer to a function that can write
> strings. The latter technique makes sure you can use the same encrypt
> routine in a GUI program as well.

Thanks for the advice...I'll need to ponder this a bit before it is
clear...I suspect it may not be until I start writing code for GUI
use. However, it does make sense. If I understand, you are saying
that I should remove *all* commands that output information to the
screen from this function, because it makes the function less
reusable?

>
> - menu.cpp
> * Get text by line and parse that, good!
> * You may want to use a std::stringstream to parse the integer, else just
> use atoi.
> * Why not print the menutext the first time from menu1 as well?
> Inconsistent.
> * You may want to flush the output stream after printing menutext, in
> trhis function you cannot be sure it is terminated with a newline.

Thanks for the advice

>
> HTH
> M4

BTW, What's HTH?? "Hate to harp"?



Relevant Pages