过度使用模板 [英] Overuse of Templates

查看:57
本文介绍了过度使用模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在点这里的帖子(希望他们会在这里!)因为

他们在comp.lang.c ++中被拒绝了。任何阅读

的人都应该首先阅读clc ++ m中相同主题的主题,以获得更多

的背景。


Ted

解决方案



" kanze" < KA *** @ gabi-soft.fr>在消息新闻中写道:11 ********************** @ z34g2000cwc.googlegr oups.com ...

Ted写道:< blockquote class =post_quotes>" kanze" < KA *** @ gabi-soft.fr>在消息中写道
新闻:11 ********************* @ i40g2000cwc.googlegro ups.com ...

> ; Sebastian Redl写道:
>> On Sun,2006年3月19日,Ted写道:>> >不好比喻。如果您认为盲目使用STL是可以的,
>> >只是这么说。我个人认为这是用
>>进行的。 >后果自负。 >>老实说,你不能使用任何你不能使用的图书馆
>>了解实施?不觉得
>>对你效率低下? >为什么要限制它到图书馆?如果你采取
>的那一点看,你不应该使用任何你没有的语言
>编写一个编译器。

或者至少避免使用特征。使编译器系统难以实现的语言。
你的意思是C ++的++部分。




你的意思是每个功能都是C ++已超过C极难实现?b $ b很难实现?

当然,你不能使用
优化器 - 好的优化比一个简单的模板实现(无需导出)。




大多数代码都不需要编译器优化是件好事

更多吧。

显然,有些人留下了标题为实现功能的难度的电子表格专栏。 (或者可能利用了
专栏?让你感到尴尬的事情。)。


>但要回到原点:在STL之前的日子里,我
>实际上实现了一个基本类库:ArrayOf,
> DLListOf和AssocArrayOf(加上其他一些 - 例如RefCntPtr,
>)。我首先用< generic.h>做了,因为那个
>就是那些日子里我们所拥有的一切。我后来用
>重新编写了它。模板。 >模板解决方案至少是一个数量级
>对于实现者来说更简单。更简单的
>用户也是。你可以不用,但它的工作量更大。

工作量增加10倍?



可能更多。非常复杂的东西,比如我的哈希
地图,对于模板来说相对微不足道,但是对于宏来说是一个真正的痛苦。




听起来像一个设计问题(你想要某种超级复杂的需要C ++模板功能的
容器?)。如果在没有C ++功能的情况下实现容器

很困难,那么我会认真重新考虑您的

容器设计。


如果你不能证明工作量超过10倍,那么我建议你再也不要说b $ b了。也许对于你来说它的工作量是你工作的10倍因为你不知道怎么做。

你真的不相信。



这不是一个相信的问题。这是具体的经验,
做散乱地图之类的非平凡的通用事物。




然后你做错了。我没有遇到任何问题。虽然好的

容器设计可以被认为是一门艺术,但这并不是最困难的b
编程问题。学习C ++这是一个很好的训练场地(和一般的编程)。

什么是真的,但是实现C ++模板系统比实现基于预处理器的模板系统要多得多。



是的,但我没有要做那个部分。




如果你将来想要(锁定)也不行。

>如果争论是某些人过度使用模板,
>并编写不可读的代码,我可以接受。我甚至
>同意。但要说< generic.h>或类似的东西,
>优于模板...没有真正使用的身体
>两者都会声称。


除了我。 :)



是什么让我怀疑你是否真的完成了宏观解决方案的任何重要工作,并尝试在任何更大的地方使用它而不是玩具应用程序。你的体验与其他人完全相反。




我认为其他人并没有想到它足够长。 (宏观解决方案实际上是不合适的。
。预处理器解决方案更准确。

也许这就是你试图实施失败的地方容器

与预处理器:你没有想到宏观概念之外的系统级别。


Ted




" Bob Bell" <是**** @ pacbell.net>在消息新闻中写道:11 ********************** @ u72g2000cwu.googlegr oups.com ...

Ted写道:< blockquote class =post_quotes>" Bob Bell" <是**** @ pacbell.net>在消息新闻中写道:
11 ** ********************@v46g2000cwv.googlegroups。 com ...

Ted写道:
Bob Bell <是**** @ pacbell.net>在消息新闻中写道:
11 ** ********************@v46g2000cwv.googlegroups。 com ...
>说真的,我得到你想要的东西。模板可以非常
>复杂。
>但它们也可以简单直接地使用。通过这种方式他们
>没有
>与其他功能不同。

就像我说的,如果我可以重现那个实现它们的黑盒子,我就可以使用它们。
如果你认为这个比喻效果很好,那就没关系了。所有它的工作原理
赢得你的论点(只在你的脑海里)。不幸的是,它缺乏实质性的相关性。你的家庭作业:考虑使用工程知识和工具的工程师与汽车的大多数驾驶员不一样。



他们在很多方面有所不同。但是,它们在一个重要方面是相似的,这是类比的重点。他们都使用了
工具,其实现细节并不像界面那么重要。只要模板的行为符合标准所说的那样,为什么有人会关心它们的实现方式?




而不是试图找到一个类比适合这个场景,你出去了

并找到了一个适合你目标的类比。

但是如果它是一个多方努力,我不得不将其视为一个不太充分的解决方案。我不是说C ++
模板不好,只是说实现是过度/不好。让它变得更好
我将使用
它。

为什么我要让它变得更好为了你?我不在乎你是否使用
模板。
我并不是说你个人,傻。



很好;为什么要有人让它变得更好为你?




这不仅仅是为了_me_。这是我的改进建议。

显然你已经拥有一套适合你的系统。




在预处理器中只有一两个小机制,但会使它更好。


特德




" Jerry Coffin" < JC ***** @ taeus.com>在消息新闻中写道:MP ************************ @ news.sunsite.dk ...

在文章< ; HLCTf.40456

I''m putting the posts that follow here (hopefully they will follow here!) because
they were rejected in comp.lang.c++.moderated. It behooves anyone reading
them to first read the the thread of the same subject in clc++m to get the more
of the context.

Ted

解决方案


"kanze" <ka***@gabi-soft.fr> wrote in message news:11**********************@z34g2000cwc.googlegr oups.com...

Ted wrote:

"kanze" <ka***@gabi-soft.fr> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...

> Sebastian Redl wrote:
>> On Sun, 19 Mar 2006, Ted wrote: >> > Bad analogy. If you think using the STL blindly is OK,
>> > just say so. I personally think that is wrought with
>> > peril. >> So you honestly don''t use any library where you can''t
>> understand the implementation? Doesn''t that feel
>> inefficient to you? > Why limit it to the libraries? If you take that point of
> view, you shouldn''t use any language for which you''ve not
> written a compiler.

Or at least avoid the "features" of a language that make a
compiler system difficult to implement.
You mean the ++ part of C++.



You mean EVERY feature that C++ has over C is extremely
difficult to implement?
And of course, you can''t use the
optimizer -- good optimization is more difficult than a simple
implementation of templates (without export).



It''s a good thing most code doesn''t require compiler optimization
any more huh.

Apparently someone(s) left off the spreadsheet column titled
"difficulty of implementing feature" (or perhaps exploited the
column? Things that make you hmmm.).


> But to get back to the original point: in pre-STL days, I
> actually implemented a library of basic classes: ArrayOf,
> DLListOf and AssocArrayOf (plus some others -- RefCntPtr,
> for example). I first did it with <generic.h>, because that
> was all we had in those days. I later redid it with
> templates. > The template solution is at least an order of magnitude
> simpler for the implementor. At significantly simpler for
> the user as well. You can do without, but it''s more work.

10 times more work?



Probably more. Significantly complicated things, like my hash
map, were relatively trivial with templates, but a real pain
with macros.



Sounds like a design issue (you wanted some kind of ultra-sophisticated
container that required C++ template features?). If implementing containers
is difficult for you without C++ features, then I''d seriously reconsider your
container design.

If you can''t prove "10 times more work", than I''d suggest you don''t say
that anymore. Perhaps FOR YOU it''s 10 times more work because you
don''t know how to do it.

You don''t really believe that.



It''s not a question of believing. It''s concrete experience,
doing non-trivial generic things like hash maps and such.



Then you did it wrong. I had no problem implementing those. While good
container design can be considered an art, it''s hardly the most difficult
programming problem to undertake. It''s good training ground to learn C++
(and programming in general).

What is true though is that implementing the C++ template
system is orders of magnitude more work than implementing a
preprocessor-based template system.



Yeh, but I don''t have to do that part.



Nor could you if you wanted to in the future (lock in).

> If the argument is that some people are overusing templates,
> and writing unreadable code, I can accept that. I even
> agree. But to say that <generic.h>, or something similar,
> is superior to templates... No body who has really used
> both would ever claim that.


Except me. :)



Which is what makes me wonder whether you have really done
anything non-trivial with the macro solution, and tried to use
it in anything larger than a toy application. You experience is
exactly the opposite of everyone else''s.



I think others didn''t think about it long enough. ("macro solution" is
actually non-appropriate. "preprocessor solution" is more accurate.
Perhaps that''s where you failed in your attempt to implement containers
with the preprocessor: you didn''t think outside of the macro concept to
the system level).

Ted



"Bob Bell" <be****@pacbell.net> wrote in message news:11**********************@u72g2000cwu.googlegr oups.com...

Ted wrote:

"Bob Bell" <be****@pacbell.net> wrote in message news:
11**********************@v46g2000cwv.googlegroups. com...

Ted wrote:
"Bob Bell" <be****@pacbell.net> wrote in message news:
11**********************@v46g2000cwv.googlegroups. com...
> Seriously, I get what you''re after. Templates can be extremely
> complex.
> But they can also be used simply and directly. In this way they
> are no
> different from other features.

Like I said, if I could reproduce that black box that implements
them, I''d
probably use them.

I''m sorry, this makes no sense. You won''t use templates because you
don''t know how to implement them? If I used your logic, I wouldn''t
drive my car. (Oops; sorry to keep going back to that "bad
analogy", it
just seems to fit remarkably well.)
If you think that analogy works well, well nevermind. All it works
well for is
"winning" your argument (in only your mind). Unfortunately, it
lacks substantive
relevance. Your homework assignment: consider how an engineer using
engineering knowledge and tools is not like the majority of drivers of
automobiles.



They are dissimilar in lots of ways. However, they are similar in one
important way, which is the point of the analogy. They are both using a
tool, the implementation details of which are not nearly as important
as the interface. As long as templates behave the way the standard says
they should, why should anyone care how they are implemented?



Instead of attempting to find an analogy that fit the scenario, you went out
and found an analogy that fit your goal.

But if it''s a multi-manyear effort, I have to dismiss it
as a less than adequate solution. I''m not saying that C++
templates are
bad, just that the implementation is overkill/bad. Make it better
and I''ll use
it.

Why should I "make it better" for you? I don''t care if you use
templates or not.
I didn''t mean you personally, silly.



Fine; why should anyone "make it better" for you?



It''s not just for _me_. It''s my suggestion for improvement is all.
Apparently you
already have a system you''re comfortable with that works well for you.



Just a teensy lil mechanism or two in the preprocessor though would make it
much nicer.

Ted



"Jerry Coffin" <jc*****@taeus.com> wrote in message news:MP************************@news.sunsite.dk...

In article <HLCTf.40456


这篇关于过度使用模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆