C++ programming
Garriss, Michael
Michael.Garriss at abacus-direct.com
Mon Oct 21 11:07:40 PDT 2002
> When misused, this can of course lead to immense bloat in the generated
> output. Any language can be misused and C++ is by no means an
> exception. But as ugly as ugly C++ is, beautiful C++ is really, well,
> beautiful :)
A great example of C++ beauty from the page 4 of the Oct 2002 C/C++ users
journal:
"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....
__________________________
/| |
|| Michael Garriss |
|| Software Engineer |
|| Contractor |
|| mgarriss at softhome.net |
||_________________________|
|/________________________/
More information about the Beowulf
mailing list