POV-Ray : Newsgroups : povray.off-topic : C++ templates to get Java-style interfaces... : Re: C++ templates to get Java-style interfaces... Server Time
14 Nov 2024 20:52:03 EST (-0500)
  Re: C++ templates to get Java-style interfaces...  
From: Darren New
Date: 20 Oct 2007 21:00:03
Message: <471aa493$1@news.povray.org>
Warp wrote:
>   That's precisely what makes templates different from inheritance. 

Yes, I know. But I appreciate the explanation. I understand it's merely 
giving more information to the compiler so it can generate error 
messages more easily, without actually changing the language.

(I'll also note there's a bunch of benefits to doing it the way Java 
does that C++ templates can't support, too, having to do with strong 
typing and dynamic loading and all that sort of stuff that C++ doesn't 
do. But that's off topic.)

>> I was more amused by example of picking different operators to aid the 
>> code generator in generating a more efficient operation for "+" than 
>> anything, tho.
> 
>   I don't really understand what's so amusing with that. No compiler is
> perfect (regardless of language).

Sure, but if your compiler for your statically-typed language doesn't 
know that for integral types
(x + x) is the same as (2 * x) is the same as (x << 1),
then I am not sure that writing macros to teach your compiler this is 
the best use of your time, rather than finding a better compiler.

As I said, it was an overly-simplistic example that amused me. Entirely 
appropriate for the article it was presented in. But it just twigged my 
"low-level hackers live here" meme. Someone once asked me how you do a 
"shift right by one byte" in Ada, and I said (x / 256). Someone else 
commented "Wow, you really think in Ada!"  I said "No, I write it the 
same way in C and BASIC and Pascal, too."

-- 
   Darren New / San Diego, CA, USA (PST)
     Remember the good old days, when we
     used to complain about cryptography
     being export-restricted?


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.