Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ tutorials for C programmers?

Reply
Thread Tools

C++ tutorials for C programmers?

 
 
Juha Nieminen
Guest
Posts: n/a
 
      02-17-2012
Ebenezer <(E-Mail Removed)> wrote:
> I agreed with Bjarne scolding some of the other panel
> members for talking at length about shared_ptr. Bjarne
> said he thinks of shared_ptr as something to be used "last".


That's also my experience. I program quite a lot in C++ as my payjob,
and *extremely* seldom do I have the need for shared_ptr or anything
equivalent.

If you have the need for shared_ptr that means you are allocating
objects individually with 'new'. Of course it may depend on the type
of application, but in practice I have noticed that needing to do so
is quite rare. In the vast majority of cases handling objects by value
is enough. If dynamic memory allocation is needed, it's usually needed
en masse, in which case you usually don't allocate the objects
individually with explicit 'new's, but instead you use one of the
standard library containers.

Perhaps GUI programming is something where allocating individual,
polymorphic objects is needed. OTOH in many cases you will usually be
using a GUI library which in itself provides the means to manage those
allocated objects...

One of the problems with shared_ptr is that it's very large in size,
compared to what it's "emulating", ie. pointers. If you create a shared_ptr
and give it an allocated object, it will take typically as much memory
as a dozen of pointers or so. Also, shared_ptr typically makes a memory
allocation in itself, so the total amount of allocations has doubled.
If you are allocating a couple of objects then that doesn't matter, but
it might matter if you are allocating millions of them (in terms of both
memory consumption and speed).
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      02-17-2012
On Feb 17, 7:16*am, Juha Nieminen <(E-Mail Removed)> wrote:
> Ebenezer <(E-Mail Removed)> wrote:


> > I agreed with Bjarne scolding some of the other panel
> > members for talking at length about shared_ptr. *Bjarne
> > said he thinks of shared_ptr as something to be used "last".

>
> * That's also my experience. I program quite a lot in C++ as my payjob,
> and *extremely* seldom do I have the need for shared_ptr or anything
> equivalent.
>
> * If you have the need for shared_ptr that means you are allocating
> objects individually with 'new'. Of course it may depend on the type
> of application, but in practice I have noticed that needing to do so
> is quite rare. In the vast majority of cases handling objects by value
> is enough. If dynamic memory allocation is needed, it's usually needed
> en masse, in which case you usually don't allocate the objects
> individually with explicit 'new's, but instead you use one of the
> standard library containers.


I may be missing something obvious, but aren't containers of pointers
useful for polymorphic dispatch?

std::vector<Shape*> picture;

and if you don't want to use raw pointers don't you end up using
shared_ptr?

> * Perhaps GUI programming is something where allocating individual,
> polymorphic objects is needed.


don't lots of other sorts of programming use lots of polymorphic
objects?

> OTOH in many cases you will usually be
> using a GUI library which in itself provides the means to manage those
> allocated objects...


your own application specific objects as well?

> * One of the problems with shared_ptr is that it's very large in size,
> compared to what it's "emulating", ie. pointers. If you create a shared_ptr
> and give it an allocated object, it will take typically as much memory
> as a dozen of pointers or so. Also, shared_ptr typically makes a memory
> allocation in itself, so the total amount of allocations has doubled.
> If you are allocating a couple of objects then that doesn't matter, but
> it might matter if you are allocating millions of them (in terms of both
> memory consumption and speed).


 
Reply With Quote
 
 
 
 
none
Guest
Posts: n/a
 
      02-17-2012
In article <(E-Mail Removed)>,
Silent Stone <(E-Mail Removed)> wrote:
>On Feb 16, 1:03 pm, yatremblay@bel1lin202.(none) (Yannick Tremblay)
>wrote:
>> Note: I do not mean that some free teaching resource might not be
>> good. Just that by limiting yourself to "free online", you might not
>> have to get money out of your wallet but you may still end up paying
>> for it in a different way.
>>

>
>On this subject, what might be some good books for someone with some
>programming experience to properly learn C++ with? I presume
>Stroustrup's book is _The Tome_ of this language? Would someone be
>better off chosing that over Accelerated C++, or Lippman's C++ Primer?


IMO, for initial learning:

Stroustrup, "The C++ Programming Language" is an excellent reference
book. It clearly and precisely explains the language and it is a book
I refer to regularly. For a professional C++ programmers, it may well
be the most used book ever. However, it is not the best
teaching/introduction book.

Koenig, "Accelerated C++" is an excellent tutorial. I would strongly
recommend it for learning C++. Its thickness (or relative lack of)
means that there a chance that the reader actually go through the
whole book rather than get bored by chapter 23, p654. OTOH, this is
not a reference book.

Lippman, "C++ Primer": Also an excellent learning book. Personally, I
prefer Koenig, however, the additonal page count of C++ Primer allow
it to go slower in places, be more explicit or have more examples and
be a bit more reference-like. As a learning book, I'd say both are
excellent and this is probably a personaly choice if you prefer more
conscise books or more explicit one.

Personally, I'd stay away from any book called "Teach yourself C++ in
[1 hour|24 hours|1 week|...]" or "C++ for [dummy|idots|...]". Any one
claiming to teach C++ in a few hours is lying and anyone claiming to
teach complex stuff to idiots is also lying.


Yannick
 
Reply With Quote
 
none
Guest
Posts: n/a
 
      02-17-2012
In article <4f3d7ea4$0$2800$(E-Mail Removed)>,
Juha Nieminen <(E-Mail Removed)> wrote:
>Yannick Tremblay <yatremblay@bel1lin202.(none)> wrote:
>> If you answer yes to both of the above, then I'd suggest you do not
>> try to learn something difficult like C++ using second class teaching
>> tools just because they are free. You will likely end up learning
>> badly or would need to spend a lot more time in order to reach the same
>> level that you would gain with top class learning tools.

>
> Recommending that one should use competent sources to learn the
>language is easy. Recommending such a source is more difficult.
>Any suggestions?


Yes, see other post.

I didn't include any book recommendation because I didn't want to
confuse the point I was making. If I'd include some book name,
peoples might diverge into ading their opinion of these books or
recommending other books.

It's like the classic TCO accounting: total cost of ownership is not
only the purchase price of the item/tool/service.

Similarly TCL: total cost of learning is not simply the purchase price
of the tutorial text.

In some circumstances, for some peoples, it might even be the paid-for
courses with an actual teacher might be better value and more
productive. In the OP case, probably not. But for a company or
someone that need to learn quickly, maybe.

Yannick




 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      02-17-2012
Nick Keighley <(E-Mail Removed)> wrote:
> I may be missing something obvious, but aren't containers of pointers
> useful for polymorphic dispatch?


They are, *if* you need polymorphic dispatch. As said, in practice
I have needed this very rarely. In the vast majority of cases handling
objects by value has been enough.

>> * Perhaps GUI programming is something where allocating individual,
>> polymorphic objects is needed.

>
> don't lots of other sorts of programming use lots of polymorphic
> objects?


Like what, for example?

GUI programming is the only type of *practical* situation where
polymorphic objects are the best and most natural solution, at least
in my own line of work. (It might be different for other types of
programming tasks.)
 
Reply With Quote
 
88888 Dihedral
Guest
Posts: n/a
 
      02-17-2012
在 2012年2月17日星期五UTC+8下午8时19分34秒 ,Juha Nieminen写道:
> Nick Keighley <(E-Mail Removed)> wrote:
> > I may be missing something obvious, but aren't containers of pointers
> > useful for polymorphic dispatch?

>
> They are, *if* you need polymorphic dispatch. As said, in practice
> I have needed this very rarely. In the vast majority of cases handling
> objects by value has been enough.
>
> >> * Perhaps GUI programming is something where allocating individual,
> >> polymorphic objects is needed.

> >
> > don't lots of other sorts of programming use lots of polymorphic
> > objects?

>
> Like what, for example?
>
> GUI programming is the only type of *practical* situation where
> polymorphic objects are the best and most natural solution, at least
> in my own line of work. (It might be different for other types of
> programming tasks.)


Don't expect average compuster users to supply
some customized method to a package to solve a problem.

The programming literacy rate is still very low now.
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      02-17-2012
On Feb 17, 12:19*pm, Juha Nieminen <(E-Mail Removed)> wrote:
> Nick Keighley <(E-Mail Removed)> wrote:
> > I may be missing something obvious, but aren't containers of pointers
> > useful for polymorphic dispatch?

>
> * They are, *if* you need polymorphic dispatch. As said, in practice
> I have needed this very rarely. In the vast majority of cases handling
> objects by value has been enough.
>
> >> * Perhaps GUI programming is something where allocating individual,
> >> polymorphic objects is needed.

>
> > don't lots of other sorts of programming use lots of polymorphic
> > objects?

>
> * Like what, for example?
>
> * GUI programming is the only type of *practical* situation where
> polymorphic objects are the best and most natural solution, at least
> in my own line of work. (It might be different for other types of
> programming tasks.)


telecommunications- end user type, simple parsers, call types

drawing maps- yes that's graphics (so sort of gui) but the graphics
package i use doesn't provide much support for custom types. It just
draws things.

don't a good chunk of the patterns in GoF use inheritance? Though
perhaps not collections of them. - ah! using a stack of Commands to
undo
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
system c/specman e tutorials Pow VHDL 1 05-11-2006 04:12 AM
Etching tutorials-or now for something completely different Technoholic Case Modding 71 09-27-2005 06:39 AM
Updated Networking Tutorials? =?Utf-8?B?UGFycm90?= Wireless Networking 3 06-20-2005 01:40 AM
PSL stmt embedded in VHDL: good tutorials somewhere? Eric DELAGE VHDL 2 04-06-2005 05:11 AM
Good books/tutorials on VHDL? Chaos Master VHDL 1 02-18-2004 09:24 PM



Advertisments