[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Good C++ beginner book



Unless the Voices are Mistaken, Josh Steele (selerius_(_at_)_codefusion_(_dot_)_org) Wrote:
> your not going to find a specific book about c/c++ on openbsd.  The
> language is portable, so once you learn it, it should work with
> anything.  A good book (IMHO) would be "Structured and Object Oriented
> Problem Soling Using C++" by Andrew C. Staugaard, Jr.  ISBN
> 0-13-028451-3  Its published by Prentice Hall if that helps.  It goes
> over the basics and some advanced topics of object oriented design
> (what you really want to learn, as c++ is totally ood) and covers some
> advanced topics..but its written for the beginner.  Of course, if you
> don't know the logic of programming, your not going to get alot...so
> you might want to pick up a basic computer logic book that goes over
> the basic logic of how a computer program works (if/else statements,
> etc.)
>
> -josh

::nail on head::

Mike doesn't indicate what his background is, just that he's been
piddling with Java and Perl. Josh makes the point though: a book does
not a programmer make, particularly (in my opinion) with C++.

One needs to have a foundation in problem solving. Can you write
instructions on how to make a Peanut Butter & Jelly sandwich without
getting PB&J on the plastic bag the bread is in?

For that I recommend "Simple Program Design, Third Edition: A Step By
Step Approach" by Lesley Anne Robertson. It's a very good book on
problem solving done entirely in psuedo code, so that you don't get
hung up on language specifics to solve a problem (because frankly:
some things in C++ syntax are just odd at that level).

Once you understand how to solve a problem, you need to have a good
grasp of the three things that make up a structured program:
        1) sequence - order code gets executed in
        2) selection - if/then/else (branching)
        3) repitition - loops: precondition, postcondition,
counter-controlled

Once you have that under your belt, you need to understand modulatity
(if you ever hope to understand encapsulation). How to break a big
problem into little, easy to chew and swallow pieces. That is also
covered in "Simple Program Design".

Got all that? You said you wanted to work in C++, so you need to (1)
thank Bjarne Stroustrup [http://www.research.att.com/~bs/homepage.html]
for extending C in 1996 and adding object orientation (among other
things), and then you need to (2) actually learn object-think.

Three things make up OOP:
        -Encapsulation
        -Inheritance
        -Polymorphism

Don't understand them inside and out? Then you might want to pick up
"The Object-Oriented Approach: Concepts, System Development, and
Modeling with UML", John W. Satzinger & Tore U. Orvik. (Unless of
course you have access to the terrible video that Borland put out in
the late 90s pitching C++ and OOP with Stroustrup on it).

So now you have a foundation in design and the basic tools of
programming, but if you want to work with C/C++ you need to embrace
(or at least understand) the things that make it so powerful, things
you don't necesicarily have in Java or Perl: Pointers and Dynamic
Memory Allocation. Understand "what" a pointer is is trivial (it's a
memory address), knowing how to use it is another.

You need to understand that given:

     struct nodeType
     {
        char data;
        nodeType* link;
     };

     typedef nodeType* nodePtr;
     nodePtr firstPtr, secondPtr;

and two lists that look like this:

  +---+     +---+---+     +---+---+     +---+---+
  |   | --> | L |   | --> | M |   | --> | T | / |
  +---+     +---+---+     +---+---+     +---+---+
    A

  +---+     +---+---+     +---+---+     +---+---+
  |   | --> | R |   | --> | P |   | --> | Q | / |
  +---+     +---+---+     +---+---+     +---+---+
    B

That the statement:

     a = b;

Will not change the values in list a, but will cause a memory leak.
You need to have an understanding how memory is allocated and
deallocated, and you need to have good habits: every time you take
memory from the free store you need to return it.

And sure, these are all things that come with time (or a semester of
Computer Science or so), but I don't ever remember hearing "DON'T
FORGET TO RETURN YOUR DYNAMICALLY ALLOCATED MEMORY TO THE HEAP IN YOUR
DESTRUCTOR" when I took Java over and over again, because Java has
that lovely garbage collector. =)

If you want a good book for C++ syntax and examples, I'm fond of "C++
How to Program" by Harvey M. Deitel and Paul J. Deitel (I like their
Java book even more). For higher level concepts in abstraction
(queues, stacks, trees, etc) I really liked "Data Abstraction and
Problem Solving with C++" by Frank M. Carrano and Janet J. Prichard.
It's based loosely on the classic "Walls and Mirrors", which I think
almost every Computer Science student had to read at one point or
another.

Hopefully, what you'll find out in your own time is that a programming
language is just an implementation of a solution to a problem. If you
want to solve a problem, and you develop a good solution, it doesn't
matter if you implement that solution in C++ or Pascal or Assembly or
COBOL (well, maybe not so much COBOL...<G>). Sure, languages have
their strengths and weaknesses, but you should be able to solve
problems irreguardless of what the tool is.

And trust me, if you've tasted the tools in Java, you're going to miss
some of them in C++. I love C++, but sometimes it's a total pain in
the ass not to be able to do:

   string inString = "43.5";
   double result;

   result = double.parseDouble(inString) / 5;

than to have to dick around with char* and char arrays and strings,
and wonder which built in conversion function wants my data in which
format?

But you know what, it's all good. It's just a tool, you should be able
to take it or leave it, right?

Good luck,
John

> On Mon, Oct 28, 2002 at 11:48:22AM -0600, Mike Shaw wrote:
> > Ok...enough piddling with Java and messing around with Perl.  I need to
> > learn C/C++, and I want to do it on OpenBSD.
> >
> > I saw a post on this a few months back, but can't seem to dig it up.  Any
> > recommendations on a good starter book that would work well on
> > OpenBSD?  One that teaches by example would be great.
> >
> > Thanks
> > -Mike

--
John W. Eisenschmidt <jweisen_(_at_)_eisenschmidt_(_dot_)_org>
   Public Key   |  http://www.eisenschmidt.org/jweisen/misc/pgp.asc
   Fingerprint  |  5F9B F916 5AD1 3295 CF99 BC1E 1F97 E6A3 37E3 BEF2
Is this mail an attachment? http://www.jensbenecke.de/misc/outlook.en.html

"Don't you want a Fanta?" --  http://www.fantanas.com/fantanas.html

[demime 0.98d removed an attachment of type application/pgp-signature]



Visit your host, monkey.org