You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by Mladen Turk <mt...@apache.org> on 2011/12/03 15:02:31 UTC

Templates ... WAS: SVN vs GIT

Instead hijacking thread ...

On 12/02/2011 06:17 PM, Leif Hedstrom wrote:
 > On 12/1/11 5:56 PM, Alan M. Carroll wrote:
 >> I suppose I can get used to git (after all, I eventually moved on from RCS). In exchange, you guys can get used to templates :-).
 >
 > Eep, that seems like a steep price to pay ;)
 >

Not that I'm for or against templates, but would
love to hear what are the technological reasons for
their exclusion/opposition/whatever.

Asking that unrelated to TS for an incubating
project that could or could not use templates.


Regards
-- 
^TM

Re: Templates ... WAS: SVN vs GIT

Posted by "Alan M. Carroll" <am...@network-geographics.com>.
I would say the #1 use case for templates is when your other choice is a lot of cut and paste. The code bloat's the same in both cases and maintenance is definitely easier in the template case.

Smart pointers are another (although those are already in ATS).

I suppose for me the standard use case is encountering a situation that requires a rule "always remember to do X" and I think "heck with that, I will make the _compiler_ remember to always do X". I do restrain myself when working on ATS, though.

I also have strong personal distaste for casting. That's half the reason I don't use APR (the other half being the lack of constructors & destructors). Although there's an example of the previous use case. Rather than me remembering to always cast, I could write a template wrapper for an APR thing (such as a hash table) that remembered to cast for me. And it doesn't even cause code bloat since it's just doing what I would have typed in myself without the template.

I would also like to note that there is already quite a bit of template code in ATS (such as lib/ts/Ptr.h and lib/ts/Vec.h).

Saturday, December 3, 2011, 7:14:59 PM, you wrote:

> I've had some nasty template breakages when upgrading gcc.
> And I don't think it was just the major version shifts (as in 3.x to 4.x).

We have had so little problem we don't even bother coordinating g++ versions on developer machines, we just use whatever happens to be installed. That could be because I have used templates so much. I remember one instance where I did some code in template style because I found it clearer until zwoop complained.


Re: Templates ... WAS: SVN vs GIT

Posted by Nick Kew <ni...@apache.org>.
On 3 Dec 2011, at 21:31, Alan M. Carroll wrote:

> We build our company product with MSVC and g++ and haven't had any serious template problems that were due to compiler issues (we have an issue where there is what *I* consider a bug in the template language specification for which MSVC has a workaround but that's not really a compiler problem). The entire STL depends on templates and is required for all conforming C++ compilers. I don't see compatibility being a real issue.

I've had some nasty template breakages when upgrading gcc.
And I don't think it was just the major version shifts (as in 3.x to 4.x).

>> I somehow tend to avoid templates myself because this is
>> the major field where compiler vendors begin
>> to dissagree on specification (or lack of it).

I actually shifted from STL to APR for a lot of classes (like map, bag, set).
No grief from gcc updates nor even other-cc since then.

But if you have a good use case where templates serve best, ...

-- 
Nick Kew

Re: Templates ... WAS: SVN vs GIT

Posted by "Alan M. Carroll" <am...@network-geographics.com>.
We build our company product with MSVC and g++ and haven't had any serious template problems that were due to compiler issues (we have an issue where there is what *I* consider a bug in the template language specification for which MSVC has a workaround but that's not really a compiler problem). The entire STL depends on templates and is required for all conforming C++ compilers. I don't see compatibility being a real issue.

Saturday, December 3, 2011, 1:49:12 PM, you wrote:

> I somehow tend to avoid templates myself because this is
> the major field where compiler vendors begin
> to dissagree on specification (or lack of it).


Re: Templates ... WAS: SVN vs GIT

Posted by Mladen Turk <mt...@apache.org>.
Thanks guys,

On 12/03/2011 06:19 PM, Alan M. Carroll wrote:
>
> P.S. I've definitely found more than one bug in a compiler (both MSVC and g++) from templates. I used to think that if I wasn't crashing the compiler with my templates, I wasn't really trying. That's become a bit harder but I expect I can get back to it when C++0xeleventy1! is generally available.
>

I somehow tend to avoid templates myself because this is
the major field where compiler vendors begin
to dissagree on specification (or lack of it).

However they might be handy in some situations which
involve mostly third party or public API thought if
properly dosed.


Regards
-- 
^TM

Re: Templates ... WAS: SVN vs GIT

Posted by Leif Hedstrom <zw...@apache.org>.
On 12/3/11 10:19 AM, Alan M. Carroll wrote:
> I have somewhat of a biased view as I was doing template style programming before C++ had templates (using the Common Lisp Object System) so it's second nature for me.
>
> P.S. I've definitely found more than one bug in a compiler (both MSVC and g++) from templates. I used to think that if I wasn't crashing the compiler with my templates, I wasn't really trying. That's become a bit harder but I expect I can get back to it when C++0xeleventy1! is generally available.

Yes, we are mainly jerking Alan around, it's what we do here. Nailed it!

But, to add to Alan's good pro's and con's, templates can be difficult to 
deal with from a cross platform perspective. If all you use is gcc, then 
fine, it's probably not a problem. But for example while I was at Netscape / 
Mozilla (which was quite a while ago), templates were generally frowned 
upon, because back then, it was virtually impossible to get them to compile 
properly in a massively multi-platform environment.

Also, templates can be difficult (in my experience anyways) to debug. The 
errors from the compilers are generally crap. And finally, templates can 
lead to code bloat (look at STL), which is totally fine for many 
applications. But for high performance apps, it should be a consideration, 
once you blow your L2/L3 caches, performance will suffer.

These are mostly my naive C++ as a C programmer points of view ;). I like 
C++, but typically because of ctor's and dtor's and encapsulation, not 
templates :).

Cheers,

-- leif


Re: Templates ... WAS: SVN vs GIT

Posted by "Alan M. Carroll" <am...@network-geographics.com>.
I think they do it mainly just to get me.

The problem with templates, as Igor touches on, is that they are a very sharp knife. In the hands of a skilled coder they can do wonderful things, but it's something that can easily get out of hand. Templates are Turing complete so you can create very expensive compilations.

Properly used templates let you avoid a lot of type casting, which is _always_ risky (although in some cases unions are a better choice). It can also cut down on cut and paste which is more of a maintenance problem than templates. In some ways it's like event oriented programming, where you end up doing things indirectly rather than straight up, with similar costs and benefits.

Fundamentally, IMHO, the point of templates is to introduce Lisp programming techniques in to C++. Whether that's a good thing is a matter of opinion.

I have somewhat of a biased view as I was doing template style programming before C++ had templates (using the Common Lisp Object System) so it's second nature for me.

P.S. I've definitely found more than one bug in a compiler (both MSVC and g++) from templates. I used to think that if I wasn't crashing the compiler with my templates, I wasn't really trying. That's become a bit harder but I expect I can get back to it when C++0xeleventy1! is generally available.

Saturday, December 3, 2011, 8:15:58 AM, you wrote:

>> Not that I'm for or against templates, but would
>> love to hear what are the technological reasons for
>> their exclusion/opposition/whatever.



Re: Templates ... WAS: SVN vs GIT

Posted by Igor Galić <i....@brainsware.org>.

----- Original Message -----
> Crap, I should have removed that email long time ago ;)
> 
> -------- Original Message --------
> To: trafficserver-dev@incubator.apache.org
> 
> Instead hijacking thread ...
> 
> On 12/02/2011 06:17 PM, Leif Hedstrom wrote:
> > On 12/1/11 5:56 PM, Alan M. Carroll wrote:
> >> I suppose I can get used to git (after all, I eventually moved on
> >> from RCS). In exchange, you guys can get used to templates :-).
> >
> > Eep, that seems like a steep price to pay ;)
> >
> 
> Not that I'm for or against templates, but would
> love to hear what are the technological reasons for
> their exclusion/opposition/whatever.

I don't think there are really technological reasons.
Oh well, except, perhaps, when John and me found a bug
in a compiler... but that happens, we're talking about
software here (:

> Asking that unrelated to TS for an incubating
> project that could or could not use templates.

The most compelling argument against templates is that
the project has mostly C hackers as committers. But
then again, wouldn't that be the most compelling argument
against using C++ to begin with? 

So in essence I think it boils down to: How confident
are your project members with C++? What language features
can you all agree on using?
 
> Regards
> --
> ^TM

So long,

i

-- 
Igor Galić

Tel: +43 (0) 664 886 22 883
Mail: i.galic@brainsware.org
URL: http://brainsware.org/
GPG: 6880 4155 74BD FD7C B515  2EA5 4B1D 9E08 A097 C9AE


Templates ... WAS: SVN vs GIT

Posted by Mladen Turk <mt...@apache.org>.
Crap, I should have removed that email long time ago ;)

-------- Original Message --------
To: trafficserver-dev@incubator.apache.org

Instead hijacking thread ...

On 12/02/2011 06:17 PM, Leif Hedstrom wrote:
> On 12/1/11 5:56 PM, Alan M. Carroll wrote:
>> I suppose I can get used to git (after all, I eventually moved on from RCS). In exchange, you guys can get used to templates :-).
>
> Eep, that seems like a steep price to pay ;)
>

Not that I'm for or against templates, but would
love to hear what are the technological reasons for
their exclusion/opposition/whatever.

Asking that unrelated to TS for an incubating
project that could or could not use templates.


Regards
-- 
^TM