[prog] School problem, C++ and cout.precision(2);

Jesika tx_kewtie at earthlink.net
Sat Nov 23 18:39:42 EST 2002


On Sat, 2002-11-23 at 02:58, Ganesh Swami wrote:

> How many people use C++ completely ? Actually very few. 
I suspect it depends on where you look.  Where I attend school, we are
taught in C++ first, and only learn the corresponding C functions in
passing.  Sure, it adds some overhead, but if you write efficient code
and use efficient algorithms, you can minimize it.  It is also much less
of an issue today than it was many years ago.  We're not talking the
difference in overhead between C and Java... the difference is really
quite negligible.  

Is it worth
> learning Templates and other advanced C++ features ?

YES!!!  Think back to the last time you wrote a linked list.  How many
functions did it require?  How many pointers did you have to keep track
of?  Whereas with the STL you can:
#inlude <list>; 
using std::list; //I don't inlude the entire namespace std... somewhat
of a headache sometimes, but it does reduce overhead.

And within your implementation:
list <int> myIntList;

Isn't that much easier?!  Same goes for queue (implemented with deque),
stack (a container adapter to limit the ability of deque by default, or
any other container specified), etc.  Then we start to get into all the
fun functions that you can perform on these using their iterators... 
AAaaahhhh... why do all this work when someone else has already written
the templates for you?  

> I believe C++ comes with its own classes for implementing stacks, hashes
> and other data structures. Does anybody use them ?

All the time!  See above.  :-)

> 
> I personally do not like streams. Its more trouble than ease. And, I
> love strongly typed languages (you can call PHP an exception ;-))
> 
> What do you people think ?

Personally, I find streams to be a really straightforward way of
handling I/O, especially when dealing with classes, where you can simply
overload the stream operator, just as you would any other operator.  It
makes a lot of sense to me, logically.  And this is coming from someone
who was EXTREMELY reluctant to embrace OOP!  

I can certainly see times when straight C is more appropriate, and I
always believe in using the right tool for the right job.  The STL isn't
inefficient by nature, though, and used properly, increases code
reusability and maintainability without heavy hits to overhead.

Jesika

-- 
-----BEGIN GEEK CODE BLOCK-----
GIT d-- s-:s+ a- C+++ UBLS++++ P- L++++ !E W N- !o ?K 
!w O M- V PS+ PE Y+ PGP++ t++ 5 X R-- tv+ b++ DI++++ D 
G e* h- r+++ x+++++ 
------END GEEK CODE BLOCK------




More information about the Programming mailing list