C++ Programming

Eray Ozkural eozk at bicom-inc.com
Mon Nov 4 00:34:12 PST 2002


Greetings,

Note that the example you gave below also demonstrates how much C++ begets 
infernal damnation with respect to language design and implementation.

As you all know some of the objectives in language design are
* orthogonality
* readability
* writability
* genericity

Your code is the perfect example of why C++ fails to meet all four of the 
above criteria. It also happens to be the most logical and clever way to 
define that particular mathematical function in C++.

Implementation-wise I cannot succeed to exhaust all aspects of complication 
and error, including total lack of program scalability.

Thanks,

On Tuesday 22 October 2002 17:11, Garriss, Michael wrote:
> 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

-- 
Eray Ozkural (exa) <erayo at cs.bilkent.edu.tr>
Comp. Sci. Dept., Bilkent University, Ankara
www: http://www.cs.bilkent.edu.tr/~erayo  Malfunction: http://mp3.com/ariza
GPG public key fingerprint: 360C 852F 88B0 A745 F31B  EA0F 7C07 AE16 874D 539C




More information about the Beowulf mailing list