Confused about learning C++

D

Daniel T.

I have no book recommendations, however, I would suggest to learn C++
concepts in the following order:

* standard library: containers, iterators, algorithms, streams.
* classes.
* function objects.
* exceptions and flow control via throw/catch.
* templates.
* smart pointers (e.g., tr1::shared_ptr<> )
* raw pointers and arrays.

I practically learned it all the other way round!

I would always advocate teaching the actual language itself before moving
on to its Standard Libraries.[/QUOTE]

Note, without the standard libraries, the student will be completely
unable to do *any* input/output, will not be able to do semi-advance
math calculations, and will not be able to do even simple string
processing...

Are you advocating that the student should have to build all the library
provided functionality him/herself?
 
T

Tomás

Is that better to read a book first on the basic concepts
of C++ language (but not the C part and not the stl part)...

If I'm ever a C++ lecturer, I will have a policy whereby students get a
whip of cane if they mention the C programming language.

In bible speak, C++ is a programming language unto itself.

If you want to learn about humans, then learn about humans. Why go
learning about homo erectus, and then proceed to learn about homo
sapiens? Just get the book called "All about Homo Sapiens".

If you want a term to describe the apsects of C++ which are common to C,
may I suggest:

Non-object orientated aspects of C++
Non-template orientated aspects of C++
Non-namespace...

-Tomás
 
B

Ben Pope

utab said:
That is fine that my thread is the most discussed one :))) but still no
reply to the original question.

We've moved away from there.
please can anyone tell me mostly the better way to follow to grasp
ideas behind the language. This was not a question for experts to
discuss their knowledge on the language :))

Well,t hats where this part of your thread has gone, feel free to ignore
it. You are allowed to start a thread, we are allowed to veer off course.
Is that better to read a book first on the basic concepts
of C++ language (but not the C part and not the stl part) that gives
the basics as if the
reader is a beginner such as

C++ Primer Plus by Prata
Teach Yourself C++ in 21 days by Liberty...

or any other book that you would recommend for first step reading.

IMO you should use the book you are using, Accelerated C++.

You haven't answered the questions posed to you by Daniel T., if you
feel you are missing out on something, or struggling with a particular
part of the book, then let us know.

Ben Pope
 
U

utab

I am not meaning not to use the std library as needed in our
applications(as needed the necessray parts can be learnt and thought)

I am just telling someone who had a good grasp of classes, operator
overloading, inheritance, polymorphism, and data structures(exercised
enough) can grasp the ideas behind the STL components better so that is
what I think the reasonable.

Thx for the replies.
 
N

Neil Cerutti

This is the basis of our disagreement.

I don't see arrays and pointers as "difficult". People learning the
Polish language may find it difficult, but the natives just yap away
without a second thought.

A benefit to learning selected portions of the library before delving
into char*, is that C++ thus appears to be a language with which a
beginner can *do* interesting things. Learning it the other way around
makes it appear to be a language that is filled with strange rules and
gotchas, in which a beginner cannot even do tasks that would take
minutes with pencil and paper.
You might stutter and stammer with arrays and pointers during the
learning process, but if you've any aptitude for this stuff at all,
you'll get the hang of it in no time.

I agree that anyone can learn it.
I frequently use arrays of "char"'s when I feel that it would be
unjustly inefficient to use an "std::string".

Have you ever been wrong in your feeling?
I exert minimal effort in using these "char" arrays, and I don't
find them difficult -- this is because I have a firm understanding
of what's going on.

I agree those skills must be learned eventually.
Arrays and pointers aren't hard.

But they are hard to learn. There is ample evidence of this posted
here nearly every week.
Don't water-down C++ tutorials just because a few learners aren't
bothered doing some real learning. It's good to separate the apt
people from the not-so-apt early on.

How is it watered down to learn standard containers and algorithms,
along with generic programming? They are powerful mechanisms. They are
a practical selection of features to learn first.

The top-down, practical approach to learning C++ is empowering. I
suppose you might fear that a programmer thus taught will *never*
learn about pointers, <cstring>, and efficiency, thus polluting your
workplace with their ignorance. But that's as illogical as if I were
to claim that the bottom-up learner shall never learns the standard
container classes.
Not all of us have the aptitude to be an exemplary programmer. If
you don't, then it is futile to pursue it. Maybe you're a good
sculptor or pianist or gymnast?

Arrays of "char"'s aren't "hackery" or "hardcore". To describe them
as such just indicates one's inaptitude.

Ridiculous.
 
D

Daniel T.

"Tomás said:
Ben Pope posted:
Perhaps. But compare a correct program for reading in the users name
and displaying it with C style char* strings and then with std::string.
Preventing buffer overrun, managing memory and everything else that
goes along with that makes it much more difficult to learn. You need to
introduce pointers, arrays, memory management etc. etc. just to write
hello world. It detracts from the relatively simple problem at hand.

Ben Pope


Valid point.

I conceed that one cannot deny the simplicity of:

void AppendHello(std::string &str)
{
str += "Hello";
}

over:

void AppendHello(char* p_char)
{
p_char += std::strlen(p_char);

*p_char = 'H';
*(++p_char) = 'e';
*(++p_char) = 'l';
*(++p_char) = 'l';
*(++p_char) = 'o';
*(++p_char) = 0;
}

I'd even use a template if possible:

template<std::size_t len>
void AppendHello(char p_char[len])
{
p_char += len;
--p_char;

*p_char = 'H';
*(++p_char) = 'e';
*(++p_char) = 'l';
*(++p_char) = 'l';
*(++p_char) = 'o';
*(++p_char) = 0;
}


If I can think in my head the way I want to manipulate a string, and can
produce the necessary code, then I'll use pointers and arrays. Yes it's more
efficient... but I also find it downright fun!

Let's try making the code equivalent before dissing the std::string
version. The thing is, we can't make an equivalent function without
using any standard libraries. How are you going to allocate memory from
the heap without #including any library files?

The below is about as close as we can come, and it *still* doesn't do
everything that the a simple str += "Hello" does.

void AppendHello( char* block, int block_size ) {
if ( block ) {
char* p_char = block;
while ( *p_char != 0 ) {
++p_char;
}
const char* hello = "Hello";
while ( p_char - block < block_size && *hello)
*p_char++ = *hello++;
*p_char = 0;
}
}
 
R

Richard G. Riley

If I'm ever a C++ lecturer, I will have a policy whereby students get a
whip of cane if they mention the C programming language.

I'm glad you are not and were not then.

IMO All programmers should get a working knowledge of C so that they
understand basic computing primitives and types. it breeds confidence,
a feel for performance and a healthy respect for memory usage
(efficiency, allocation and deallocation) : all skills severely
lacking in a LOT of newer programmers.

In bible speak, C++ is a programming language unto itself.

With standard libraries maybe.
If you want to learn about humans, then learn about humans. Why go
learning about homo erectus, and then proceed to learn about homo
sapiens? Just get the book called "All about Homo Sapiens".

If you want a term to describe the apsects of C++ which are common to C,
may I suggest:

Non-object orientated aspects of C++
Non-template orientated aspects of C++
Non-namespace...

-Tomás

What does "non-namespace" mean here?
 
G

Gavin Deane

Tomás said:
Looking at the "Hello World" example:

#include <iostream>

int main()
{
std::cout << "Hello World!";
}


I've always thought this was a horific piece of code to throw in front of a
beginner. I started out programming in Visual Basic when I was about twelve,
and then when I moved on to C++, I was greeted with this really weird way of
printing things to the screen. I hadn't a clue what the craic was with the
"<<".

To trully understand how "cout" works, one has to understand operator
overloading. Only then can one realise, "Oh yeah, they overloaded the bit-
shift operator to make it look like you're putting things toward cout".

This is the basis of our disagreement.

Who cares about truly understanding how cout works? The point is that
by utilising the tools provided by the standard library from the outset
a C++ student can immediately be more productive in creating correct,
clear programs, which is the goal of all programming. An understanding
of what is really going on in that statement - what is cout, what is
<<, what is overloading and how is it achieved - can be left until much
later without imparing their ability to write programs. Exactly the
same argumant applies to dynamic arrays vs vectos, char* vs strings
etc.

As for recognising << as a bit shift operator, that might be the case
for someone with previous experience of C. In that case, issues like
char* vs string is not so much to do with what is easiest to learn (a C
programmer will already know how to use char arrays). The issue is what
helps you write correct code more easily that will potentially be
maintained by C++ programmers who do not have a C background.

A complete novice will not recognise << as a bit shift operator. To
them it will be the stream insertion operator, which is no bad thing,
since that is often its main use. Later they will encounter its use in
bit shifting. If operator overloading has come up already this can be
shown as an example. It's not particularly important which is the core
language meaning and which is the library overload at this stage.
When I first saw the statement, I hadn't a bull's notion what "cout" was. Is
it an object? Is it a class? Is it Superman?

I'd re-assure learners that the whole "cout <<" thing should *indeed* appear
very strange to them, but that they should just accept that that's how it is
until they learn operator overloading, at which point everything will become
abundantly clear.

Operator overloading should not be mentioned unless you are teaching C
programmers who already know << to mean something else.

The real problem is one of primacy. Unless you put in concious effort
to avoid it, you will innately fall back on what you learn first.

When writing a C++ program, for clarity, correctness and robustness,
vector should always be the default preference over a dynamic array and
string should always be the default preference over char* (which is
certainly hackish). If you teach them the wrong way round, there is the
risk that the standard library components will be regarded as clever
and advanced variations. The student's natural way of thinking about
programming with strings will be char*, because that's what they learnt
first. It's certainly possible to break this backwards thinking, but
why introduce the need when it can be avoided so easily?

WIth C programmers learning C++, the primacy battle is already lost and
the only option is to break the entrenched backwards thinking. All the
more reason to hammer home the point early and hard and often.

Gavin Deane
 
J

Jerry Coffin

utab said:
That is fine that my thread is the most discussed one :))) but still no
reply to the original question.

please can anyone tell me mostly the better way to follow to grasp
ideas behind the language. This was not a question for experts to
discuss their knowledge on the language :))

Is that better to read a book first on the basic concepts
of C++ language (but not the C part and not the stl part) that gives
the basics as if the reader is a beginner such as

If you're starting from ground zero, and haven't done any programming
before at all, I'd suggest _You can do it_, by Francis Glassborrow. If
you've done some programming before, then I'd suggest skipping that and
going directly to _Accelerated C++_ (by Koenig and Moo).
C++ Primer Plus by Prata

I'm not sure, but IIRC, when I glanced through this in the book store,
it didn't impress me a lot. I wouldn't say it's a terrible book by any
means, but it didn't impress me as a particularly good one either.
Unless memory serves me even worse than usual today, it's built on the
assumption that you have some (but not necessarily much) previous
programming experience, and if that's the case, I'd say _Accelerated
C++_ is a lot better place to start.
Teach Yourself C++ in 21 days by Liberty...

If I were a better person, I wouldn't recommend this to anybody. As it
is, I might recommend it, but only to somebody I thoroughly despised.
 
D

Daniel T.

"utab said:
I am not meaning not to use the std library as needed in our
applications(as needed the necessray parts can be learnt and thought)

You can't write a anything useful without including at least some
library. Are you advocating using only non-standard libraries?

I am just telling someone who had a good grasp of classes, operator
overloading, inheritance, polymorphism, and data structures(exercised
enough) can grasp the ideas behind the STL components better so that is
what I think the reasonable.

What is it that you are having trouble grasping? I'm looking at the
exorcises for chapter 7 and I don't see anything where knowledge of
classes, operator overloading, inheritance, or polymorphism would help.
As for data structures, that was covered in an earlier chapter.

Maybe the book is going too fast for you? Explain the problem and we'll
try to help. (at least I will.)

However, to once again answer your original question:

Is that better to read a book first on the basic concepts of C++ language
(but not the C part) that gives the basics as if the reader is a beginner

That is exactly what "Accelerated C++" does. It assumes the reader is a
beginner at C++ (though maybe not a beginner programmer) and teaches you
the language. However, if you are having trouble grasping some of the
concepts, that's understandable, the book doesn't spend much time on any
of them, but kind of breezes over them. What concepts are you having
trouble with? I'll be happy to help out. Since you are on chapter 7, is
it something about associative containers that is giving you trouble?
 
R

Roland Pibinger

You know, I know... What a pitty you still refuse the cooperation :)

Well, you not only invented your own library but also your own
language (pick semantics, Moveable, PolyDeepCopyNew, ...), tailored
for your needs and ideas. What suits you well may not suit others
equally well. Anyway, the result of your effort, Ultimate++, is
respectable.

Best wishes,
Roland Pibinger
 
U

utab

Not related with the exercises of chapter 7
I have not finished Chapter 7 yet and May I ask you a question, how
long have you known C++ and from where you get started.

I got started with Teach yourself C++ in 21 days did not like it
I read also C++ primer plus until chapter 10 but most of it was known
before me so skipped that
I read some parts of C++ Programming Language it went over my head.
I got the book Deitel C++ How to Program from the library it seems fine
but many pages :((
Accelerated C++ is OK to what extent your programming knowledge is up
IMHO. Maybe it is a bit high level for me even if I did C coding for
numerical problems

This became a thread on the books about C++ not the language :((
 
M

Mirek Fidler

Roland said:
Well, you not only invented your own library but also your own
language (pick semantics, Moveable, PolyDeepCopyNew, ...), tailored
for your needs and ideas.

Interesting point of view, however the same can be said about STL... If
you are going so solve some issues, you have to introduce some new
features and concepts... (and no, there are of course no changes to the
core language).

BTW, I have seen you have implemented your own owning container, similar
to U++ Array... How you are solving deep copy of container full of
polymorphic values? (if you allow them) (this about PolyDeepCopyNew
issue...)

Mirek
 
R

Roland Pibinger

Interesting point of view, however the same can be said about STL... If
you are going so solve some issues, you have to introduce some new
features and concepts... (and no, there are of course no changes to the
core language).

When the copy constructor 'picks' the the original then you change
usual language semantics. 'Copy' usually means 'duplicate'.
BTW, I have seen you have implemented your own owning container, similar
to U++ Array...

Not quite. My container owns nothing. Owning containers ("smart"
containers) that require transfer of ownership usually run into
trouble.
How you are solving deep copy of container full of
polymorphic values? (if you allow them) (this about PolyDeepCopyNew
issue...)

One needs to distinguish between 'value types' and (possibly
polymorphic) 'entity types'. The latter have state and identity and
are usually not copyable. I know, there are situations where you want
to copy (in the meaning of 'duplicate' not 'pick') entity objects. But
that should be an exception, not the rule. I would prohibit copying
for containers of polymorphic contents.

Best wishes,
Roland Pibinger
 
D

Daniel T.

"utab said:
Not related with the exercises of chapter 7
I have not finished Chapter 7 yet and May I ask you a question, how
long have you known C++ and from where you get started.

I first started learning C++ back around 1993, about 2 years after I
began learning C. I probably read every "learn C++" book that existed at
the time so I couldn't really say which book(s) I got started with. I
know I owned "C++ for Dummies" at one point, it may have been one of the
first books I bought on the language, however I also read every C++ book
that I could get through inter-library loan, so it was far from the only
one I used.
I got started with Teach yourself C++ in 21 days did not like it
I read also C++ primer plus until chapter 10 but most of it was known
before me so skipped that

I skimmed through it at the library long ago, and wasn't impressed.
I read some parts of C++ Programming Language it went over my head.

That book needs to be read more than once.
I got the book Deitel C++ How to Program from the library it seems fine
but many pages :((

It's a big language...
Accelerated C++ is OK to what extent your programming knowledge is up
IMHO. Maybe it is a bit high level for me even if I did C coding for
numerical problems

I'm not sure what you mean by "high level", I figure you mean that it
makes a lot of assumptions about how quickly you can learn and what
other resources you have. IMHO, the book would work best in concert with
a teacher/tutor who is providing lots of extra examples and projects.
Most people need to be exposed to a topic multiple times before it
starts to sink in...
This became a thread on the books about C++ not the language :((

Ask a vague question and your thread is likely go all over the place.
 
M

Mirek Fidler

Roland said:
When the copy constructor 'picks' the the original then you change
usual language semantics. 'Copy' usually means 'duplicate'.

Same is true for auto_ptr.

Also, in U++ lingo, it is not copy-constructor but pick-constructor.

BTW, future C++ will very likely have similar functionality (r-value
references). Of course, it will change the core language so the solution
can be much more elegant (there will be "move constructor"). Without
being able to change the core language, one does best he can :)
Not quite. My container owns nothing.

Sorry, I reviewed it only briefly and concluded that ptr_vector_owner is
the owning variant (that would seem logical to me - safer and easier to
use - helper classes like that can get tricky).
Owning containers ("smart"
containers) that require transfer of ownership usually run into
trouble.

That is why you definitely need pick (or move) instead of (or alongside
with) copy....
One needs to distinguish between 'value types' and (possibly
polymorphic) 'entity types'. The latter have state and identity and
are usually not copyable. I know, there are situations where you want
to copy (in the meaning of 'duplicate' not 'pick') entity objects. But
that should be an exception, not the rule.

I agree, it is an exception.
I would prohibit copying
for containers of polymorphic contents.

Actually, that is not that bad solution either. In my whole code-base
(more than 20MB of C++), this feature was used just once. However, at
the time of design it seemed like the gap that should be closed.... and
the solution was possible. It is perhaps a good candidate for removal in
the next iteration....

Mirek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top