C++ programming

Garriss, Michael Michael.Garriss at abacus-direct.com
Mon Oct 21 12:16:22 PDT 2002


Giving up on something because you don't immediately understand it is
probably not a great strategy for success.

myMap is a map< string, int >, which maps string to ints (example
myMap["Kevin"] = 14 maps the string "Kevin" to the value 14).  The ++
operator applied to ints adds one to the value.  Thus myMap[key]++ adds one
to the int variable that key maps to.  Not too tough.  Take the time to
learn or at least look into C++ and you might be surprised.

-Mike

-----Original Message-----
From: Kevin Cole [mailto:kjcole at gri.gallaudet.edu]
Sent: Monday, October 21, 2002 1:09 PM
To: Garriss, Michael
Cc: 'Jakob Oestergaard'; Eray Ozkural; 'Alan Scheinine';
beowulf at beowulf.org
Subject: RE: C++ programming



Without knowing either lanugage, I look at the C++ version and say
"Huh?" Whereas when looking at the Java version, I at least can make
some guess as to what it does.  The example provided is exactly what
keeps me away from C++ and the like: Instead of learning a few commands
and manipulating them, one memorizes the bible, the dictionary, and the
thesaurus (or searches through some tome -- electronic or hardcopy).  
IDE's or whatever may help search the tome, but still...

Granted, the wheels that people reinvent may not be the ideal wheel, and
there'll be a lot of variations in design.  I can see where that would
be a disadvantage if you do a lot of shipping your code around to the
four corners of the universe.

> "Consider the now-trite "word count" program that uses a map data
structure
> to keep track of the number of instances of each word in a document.  In
> Java, a language not known for its economy of expression, you'll need code
> something like the following to process a word:
> 
> if ( !myMap.containsKey( key ) )
> 	myMap.put( key, new Integer( 1 ) );
> else {
> 	Integer count = (Integer) myMap.get( key );
> 	int icount = count.intValue( );
> 	myMap.put( key, new Integer( ++icount ) );
> }
> 
> whereas in C++ it is simply:
> 
> myMap[key]++;
> 
> More expressive power begets higher-level programming, which in turn leads
> to elegant, readable code."
> 
> I would love to see the FORTRAN version of this code....

	CALL something_I_write_and_understand (...)

;-)



More information about the Beowulf mailing list