C++ Programming

Garriss, Michael Michael.Garriss at abacus-direct.com
Tue Oct 22 07:11:30 PDT 2002


Good points.  However I would disagree with your claim that "It ALL depends
on the implementation."  Not true.  I'm not an expert but I believe some
languages can not be optimized in certain ways because of the language
itself.  For example, C++ metaprogramming, you could say....determine the
factorial of some X at compile time with this:

template< int n >
struct factorial
{
	enum { result = n * factorial< n-1 >::result };
};

template<>
struct factorial< 0 >
{
	enum{ result = 1 };
};

int main( ) {
	std::cout << factorial< 5 > << std::end
	          << 120 << std::endl;
}

This produces:

120
120

That factorial calculation is ZERO runtime cost.  Not one cycle.  Some
languages have no way to do this.

-Mike Garriss

-----Original Message-----
From: J. R. Valverde [mailto:j at cnb.uam.es]
Sent: Tuesday, October 22, 2002 5:07 AM
To: beowulf at beowulf.org
Subject: Re: C++ Programming


Just my 2¢ in all this nonsense:

First, about trust:

	NEVER EVER trust the computer to do the right thing. A computer is
a device designed by humans to run programs written by humans. Humans make
mistakes. Dot.

	It never pays trusting a compiler. Or a language. That's utter
nonsense. You may "rely" on your experience using a tool to assume it
often does the right thing, but that's all.

Second about optimization:

	Unless you can look under the hood (and you do), NEVER EVER assume
one optimizer is better than other. Or that a language may be better
optimized
than other. It all depends on the implementation, which in turn depends on
the ability of the author(s), which turn out to be humans.

Bottom line:

	Whatever you are doing: if you can, try a few tools and see which
one
works better for you *at that particular problem* (where "problem"
encompasses
all, the abstract, practical, compute problems AND the sociological,
environment,
etc... aspects as well).

	I'm not going to recall horror stories now.

				j


-- 
	These opinions are mine and only mine. Hey man, I saw them first!

			    José R. Valverde

	De nada sirve la Inteligencia Artificial cuando falta la Natural
_______________________________________________
Beowulf mailing list, Beowulf at beowulf.org
To change your subscription (digest mode or unsubscribe) visit
http://www.beowulf.org/mailman/listinfo/beowulf



More information about the Beowulf mailing list