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

From: Martijn Lievaart (m_at_rtij.nl.removefromhere.invalid)
Date: 11/07/03


Date: Fri, 07 Nov 2003 10:30:26 +0100

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.

g++ -c -o J_Crypt.o J_Crypt.cpp
In file included from J_Crypt.h:9,
                 from J_Crypt.cpp:1:
hashSclass.h:6:30: alignint_class.h: No such file or directory
In file included from J_Crypt.cpp:1:
J_Crypt.h:10:30: filespec_class.h: No such file or directory
J_Crypt.h:15:23: encrypt.h: No such file or directory
In file included from J_Crypt.h:16,
                 from J_Crypt.cpp:1:
unencrypt.h:9:26: HashSclass.h: No such file or directory
unencrypt.h:13:30: filespec_class.h: No such file or directory
In file included from J_Crypt.h:16,
                 from J_Crypt.cpp:1:
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. :-)

A quick look on some random chosen files.

- hashSclass.h
You only need <string>, move all the other #includes to the C++ files.

- 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.

- 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.

- 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.

HTH
M4



Relevant Pages

  • Re: Nasty code...but please critique it anyway :-)
    ... You only need <string>, move all the other #includes to the C++ files. ... compilation times. ... You may want to use a std::stringstream to parse the integer, ... You may want to flush the output stream after printing menutext, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Help With PyParsing of output from win32pdhutil.ShowAllProcesses()
    ... None to a string). ... Still have an urge to parse with pyparsing? ... pyparsing Dict class. ... keys from the parsed data, so it looks like you are already thinking ...
    (comp.lang.python)
  • Re: Pyparsing help
    ... our grammar isn't parsing the METAL2 entry at all. ... input string". ... successful parse, then restored half of the entries I removed, until I ... Layer PRBOUNDARY ...
    (comp.lang.python)
  • Re: Parsing a string
    ... to parse names. ... > I didn't have the errorhandler in testing, ... > records and the function encounters an error, ... strPrefix As String ...
    (microsoft.public.access.queries)
  • Re: Polymorphism in Java SE?
    ... In both cases, there's a common parent type ... actually have to do instanceof - just use the methods on the parent type. ... In practice, you ALWAYS want the String, then parse it to a more specific ...
    (comp.lang.java.programmer)