templates in C++

Started by
27 comments, last by MARS_999 21 years, 5 months ago
What the fuck is wrong with these people. Somebody makes an observation, expresses an opinion, POOF!

He''s the devil incarnate.

Perspective, people.
daerid@gmail.com
Advertisement
if you look at peoples profiles you can see that some people just say daft stuff and never come back for a follow up post
quote:Original post by petewood
if you look at peoples profiles you can see that some people just say daft stuff and never come back for a follow up post


Really??? I made the observation since I am learning templates and from what I have read looked like an easier way to code a function to accept many different data types. I will 99% of time go with easier isn''t always better. So thats why I asked why is templates so great. I can see the need for operator overloading I kind of like them. They make sense and are not quite as generic. BTW never said I was a C++ expert.

"You have Freedom, sir"
"Were do I have freedom"
"Only in your head, we control the rest of your body and life for now"
"My FREEDOM isn''t for sale"
quote:Original post by muer
Naw, we actually use that stuff.... but... but.... macros?!?!
Macros give the illusion of being a function call, while still being able to use compile-time constants. Although I'd normally leave macros out altogether, they do have their use in explaining template metaprogramming to mere mortals.

quote:Original post by daerid
What the fuck is wrong with these people. Somebody makes an observation, expresses an opinion, POOF!
This insanity again?

If someone reaches a conclusion before asking for the facts, this is the risk they take.

[edited by - Beer Hunter on October 21, 2002 6:34:37 PM]
quote:Really??? I made the observation since I am learning templates and from what I have read looked like an easier way to code a function to accept many different data types.

And this is bad why?

What do you feel is the advantage of writing each function separately?

quote:I will 99% of time go with easier isn''t always better.

Why?

quote:So thats why I asked why is templates so great.

Because, amongst other things, they mean you don''t have to write the same function or class over and over and over again.

quote:I can see the need for operator overloading I kind of like them.

Templates are IMO one of the more important uses of ad hoc polymorphism. That is to say, templates transform operator overloading from being simply nice syntactic sugar into something genuinely useful and damn near irreplacable.

quote:They make sense and are not quite as generic. BTW never said I was a C++ expert.

So much is evident.

Tell you what, how about you start actually justifying your opinion?

You appear to think that their being for lazy programmers is a Bad Thing. Why?

You appear to think that a templated function will be slower than equivalent hand-written overloads. Why?

You appear to think that the easier a solution is, the more likely it is to be inferior. Why?
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
For the Love All that is Good, do as Thumper''s says!
("If you don''t have anything nice to say, don''t say anything at all")

I didn''t find Mars'' original post presumptuous at all. He simply asked what templates are good for - seems reasonable to me.

In fact, let us dissect his message, with Asking Smart Questions in mind:
"After reading up on templates..."
He has asserted that he is making an effort to understand something new.

"...I have come to the conclusion that they are for lazy programmers."
If by accident, the young grass-hopp''r is most-wise.

"I don''t see the difference if you were to code a function to take explicit parameters vs. general parameters."
Note the emphasis ‘I don’t understand’. The conclusion is valid as well (*logic majors, please note the technical difference between valid and sound arguments.) – you can achieve the same results as template functions using explicit parameters and overloading. He''s begging the presentation of a useful template function.

"Just seems lazy and a faster way to whip up some code, and most likely its slower since it has to make up a new function for each type of data that is passed as a parameter."
Again, notice the non-declarative voice and uncertainty, this is an implied question.

"Unless someone can help me see the light I don''t see the need for templates in game programming."
Again, it is clear that he has not ''passed judgment'', and is asking for some help.

"Thanks"
Wow, even polite to boot!


...
Matt, I would be inclined to respond very similar to Cyberdrek to the way you did, but it would have involved a pearl and been considerably more vulgar. This is a good time to remind everyone (myself inclusive), that there are some women that visit the boards, young teenagers, and time-to-time even children. It''s probably best they don''t ever hear the pearl line (if you''re dying to know, send me email, but I don''t want any angry rants from parents or teachers about the filthy things their kids are learning on the Internet).
The period thing is a sensitive issue for many women... the sardonic nature is often overlooked and it''s viewed as a sexist remark.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:I will 99% of time go with easier isn''t always better.

You''ve inverted your logic there. 99% of the time, easier is better. KISS.

Keep
It
Simple
Silly (yes, I''m being nice today)

It''s a mantra. Live by it. If you go the hard way, expect to be held back in class and/or business.
quote:Original post by MARS_999
Really??? I made the observation since I am learning templates and from what I have read looked like an easier way to code a function to accept many different data types.

OK, calm down. The best way to answer a question like you asked way back is to find out for yourself. Try learning a bit about templates and using them in your programs. Remember the guideline "do the simplest thing that can possibly work", which often precludes the use of templates as an initial solution, but not that templates can provide a valid refactoring to escape code replication. Above all, be diligent in design but lazy in implementation. Lazy is cool.
quote:Original post by SabreMan
Original post by MARS_999
Really??? I made the observation since I am learning templates and from what I have read looked like an easier way to code a function to accept many different data types.

OK, calm down. The best way to answer a question like you asked way back is to find out for yourself. Try learning a bit about templates and using them in your programs. Remember the guideline "do the simplest thing that can possibly work", which often precludes the use of templates as an initial solution, but not that templates can provide a valid refactoring to escape code replication. Above all, be diligent in design but lazy in implementation. Lazy is cool.

Thanks SaberMan, I will have to work with templates more to see what I can come up with. For the rest of the people who have posted and been bitching about the thread, instead of bitching maybe you should answer the question that was asked? No one has give me any examples on why one would use templates for games? Thanks

"You have Freedom, sir"
"Were do I have freedom"
"Only in your head, we control the rest of your body and life for now"
"My FREEDOM isn''t for sale"

This topic is closed to new replies.

Advertisement