Understanding Templates: why can't anybody do it?
H. S. Teoh
hsteoh at quickfur.ath.cx
Sat Mar 17 15:39:53 PDT 2012
On Sat, Mar 17, 2012 at 09:45:51PM +0100, Gour wrote:
> On Sat, 17 Mar 2012 21:29:18 +0100
> Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
>
> > I had no idea what templates were when I started using D, and I
> > thought I would never need to use them either. But now I use them
> > extensively. They really become a natural tool in programming.
> > They're so nice to use that I never have to reach for the big fat
> > OOP monster, I can just write simple procedural code and use
> > templates when I need some flexibility.
>
> Thank you for this paragraph. ;)
>
> I also consider to write procedural/functional code in my project and
> leave OOP behind, so it's nice to know that templates are the way to
> go.
[...]
I don't think you can discard OOP entirely. It still has its place IMO.
When you need runtime polymorphism, OOP is still the best tool for the
job.
But yeah, quite often you don't need full-fledged runtime polymorphism,
just a little compile-time flexibility (contrary to what the OO zealots
would have you believe). D templates are more than suitable for the job.
Using OO for this kind of thing just introduces unnecessary bloat and
slow performance.
(Not to mention, D templates can do some stuff that no OO can hope to
attain. But it goes both ways. Templates can't do runtime polymorphism
either.)
T
--
Sometimes the best solution to morale problems is just to fire all of the unhappy people. -- despair.com
More information about the Digitalmars-d
mailing list