使用 STL 与自定义实用程序类的程序员生产力

发布于 2024-07-14 17:19:30 字数 293 浏览 3 评论 0原文

在我工作的环境中,由于历史原因,我们使用的是自定义实用程序类的大杂烩,其中大部分是在 STL 出现之前编写的。 我认为至少使用 STL 编写新代码是个好主意的原因有很多,但最主要的是我相信它可以提高程序员的生产力。 不幸的是,我不知道如何证明这一点。

是否有任何研究试图量化甚至只是暗示使用 STL 所带来的生产力提升?

更新:我想我应该更具体。 我提倡重写现有代码,并且我担心新员工能否顺利开始。 前者是愚蠢的,而后者本身并不足以让人信服。

I work in an environment where, for historical reasons, we are using a hodgepodge of custom utility classes, most of which were written before STL arrived on the scene. There are many reasons why I think it is a good idea to at least write new code using STL, but the main one is that I believe it increases programmer productivity. Unfortunately, that is a point that I don't know how to prove.

Are there any studies out there that attempt to quantify, or even just hint at, a productivity gain from using STL?

Update: I guess I should have been more specific. I am not advocating rewriting existing code, and I am not worried about the new hires that will get a running start. The former would be foolish, and the latter by itself is not enough to convince people.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

情绪操控生活 2024-07-21 17:19:30

没有研究表明 STL 仅仅因为它是 STL 就更高效。 使用它可以提高生产力,因为它是程序员熟悉的标准,并且代码已经编写和测试过。

如果您的公司已经拥有员工熟悉的实用程序类,并且该实用程序代码在整个现有代码库中使用,那么切换到 STL 实际上可能会降低生产力。

也就是说,对于使用 STL 的新代码来说将是一个很好的举措。 我不一定会从生产力的角度来争论这一点,而是从可维护性的角度来争论。 如果您拥有早于 STL 的代码,听起来您公司的代码具有相当长的生命周期,并且多年来可能由许多新程序员维护。

您可能还想提倡使用 STL 作为每个人保持 C++ 技能的一种方式。 虽然我不会拒绝不懂 STL 的 C++ 候选人,但我肯定会将其视为一个污点。

There are no studies that will show STL is more productive just because it is STL. Productivity gains from using it are due to it being a standard programmers are familiar with it, and because the code is already written and tested.

If your company already has utility classes that employees are familiar with, and this utility code is used throughout an existing codebase, then switching to STL could actually be detrimental to productivity.

That said for new code using STL would be a good move. I would not necessarily argue this from a productivity standpoint, but one of maintainability. If you have code that predates STL it sounds like code at your company has quite a long lifetime and is likely to be maintained by a number of new programmers over the years.

You may also want to broach the use of STL as a way for everyone to keep their C++ skillset sharp. While I wouldn't reject a C++ candidate who didn't know STL, I would definitely view it as a black mark.

倾`听者〃 2024-07-21 17:19:30

STL之所以如此“好”,只是因为它已经存在很长时间了,并且它的实现已经得到了很多用户和关注。 它们经过了良好的调试,并且供应商对算法进行了很好的优化。

STL 对于您商店中的新开发人员来说会更有效率,因为他们可能已经熟悉它了。 您的自定义库将是外国的,并且可能缺乏开发人员习惯使用的功能。 不过,对于新开发人员来说,在最初的磨合期之后,这并不是一个大问题。

没有真正迫切的理由要转向 STL,因为它确实如此。 如果您的应用程序中有非常有用的实用程序类,我建议您坚持使用它们,除非它们不适用于新代码。 在新代码中将 STL 与自定义库混合会在某些时候导致兼容性问题,并且重构代码以使用所有 STL 会引入错误。 无论哪种方式,你都会失去生产力。

编辑:“新”代码是指使用旧类库的现有应用程序中的新代码。

如果您正在开发不利用任何旧应用程序代码的新独立应用程序,我会推荐 STL,因为它就在那里,大多数 C++ 开发人员都知道如何使用它,而且它非常稳定(并且您可以从工具集供应商那里获得支持)如果不是)。

The reason the STL is so "good" is simply because it's been around a long time now and the implementations have seen a lot of users and eyes. They're well debugged and the algorithms have been pretty well optimized by vendors.

STL will be more productive for new devs in your shop because it's likely they are already familiar with it. Your custom libs will be foreign and probably lacking in features that devs are accustomed to using. That's not a huge issue after the initial ramp-up period for new devs though.

There's no real pressing reason to shift to STL just because it is. If you have perfectly useful utility classes in your application I'd recommend sticking with them unless they're not workable for new code. Mixing STL with your custom libraries in new code is going to cause compatibility problems at some point and refactoring the code to use all STL is going to introduce bugs. Either way you'll be losing productivity.

Edit: By "new" code, I mean new code in existing applications using the older class libraries.

If you're developing new standalone apps that do not draw on any of the old applicaiton code I'd recommend STL because it's there, most every C++ dev knows how to use it and it's pretty stable (and you get support from your toolset vendor if it's not).

愁以何悠 2024-07-21 17:19:30

我能想到的使用 STL 提高生产力的唯一论点是轻松集成其他库的可能性 - Boost、Arabica、SOCI 等。它们都是为与 STL 一起工作而设计的,而不是与您的内部容器类一起工作。

The only argument for increasing productivity with STL I can think of would be a possibility of integrating other libraries easily - Boost, Arabica, SOCI, etc. They are all designed to work with STL, not your in-house container classes.

呢古 2024-07-21 17:19:30

我认为关键因素是开发团队的流动率。

如果团队稳定,并且他们已经在该代码上工作了十年,并且可能从现在起十年后,他们将使用他们熟悉的实用程序类提高工作效率,并推动他们使用 STL 将导致生产力下降和错误。

如果团队变动较多,那么新的开发人员可能会熟悉 STL,而显然不是这个专有的实用程序类库,并且会用 STL 做得更好。

I think the critical factor is the turnover rate of the development team.

If the team is stable, and they've been working on this code for ten years and probably will be ten years from now, they will be more productive using the utility classes they're familiar with, and nudging them to use the STL will result in reduced productivity and bugs.

If the team turns over a lot, then the new developers will likely be familiar with the STL, and obviously not this proprietary utility class library, and will do better with the STL.

感情旳空白 2024-07-21 17:19:30

我也遇到过同样的情况。 这取决于相关的实用程序类。 我见过的许多自定义实用程序类都存在错误或设计不当,并且导致整个源代码出现错误和效率低下。 在这种情况下,直接替换为 STL 等效项将改进代码库、提高生产力、减少错误并降低未来的维护成本。

有时,您可以通过为旧类改造 STL 风格的迭代器来帮助弥合两个世界之间的差距,但要小心确保它们正确!

I have been in the same situation. It depends on the utility classes in question. Many custom utility classes I have seen have been buggy, or poorly designed, and are causing bugs and inefficiencies throughout the source. In this case, a straight replacement with STL equivalents will improve the codebase, increase productivity, decrease bugs and reduce maintainance costs for the future.

You can sometimes help to bridge the gap between the two worlds by retrofitting STL-style iterators to your old classes, though be careful to get them right!

动听の歌 2024-07-21 17:19:30

如果本地开发的实用程序以任何方式特定于您所做工作的领域,情况可能恰恰相反。

It may be that the reverse is true where the home-grown utilities are in any way domain-specific to the work you do.

睫毛溺水了 2024-07-21 17:19:30

STL 有用的地方不是在 STL 提供的实际库等中,而是在 STL 使用的编码风格中。

下面需要进行 2 个主要测试:

struct DoSomething {
  bool operator ()(Container::value_type const & v) const
  {
    // ...
  }
};

void bar (Container const & c)
{
  std::for_each (c.begin (), c.end (), DoSomething ());
}

第一个测试验证 'DoSomething::operator()' 是否执行了它应该执行的操作。 第二个测试只需要验证“DoSomething::operator()”是否被调用。

与手写的 for 循环相比,这种分离有助于提高生产率。 对于上述情况,测试数量是“要做的事情”和对非空容器进行调用的测试的总和。 在 for 循环的情况下,测试次数是测试的乘积。

One place where STL is useful is not in the actual libraries etc that are provide by STL but rather in the coding style that STL uses.

In the following there are 2 main tests required:

struct DoSomething {
  bool operator ()(Container::value_type const & v) const
  {
    // ...
  }
};

void bar (Container const & c)
{
  std::for_each (c.begin (), c.end (), DoSomething ());
}

The first tests verify that 'DoSomething::operator()' does what it's supposed to do. The second test only needs to verify that 'DoSomething::operator()' is called.

This separation can help improve productivity when compared with a hand written for loop. For the above, the number of tests is the sum of the "thing to be done" and the tests that the call is made for a non empty container. In the case of the for loop the number of tests is the product of the tests.

傲世九天 2024-07-21 17:19:30

我认为的原因是:

代码的质量

STL 的编写者(无论是其接口,还是编译器的实现)无疑比贵公司中最好的开发人员要好得多。

他们的工作是制作一个可用的 STL,这意味着每个函数/方法/对象无论如何都经过严格测试。

代码的可维护性

随着人员的更替,一些代码可能会慢慢地、悄悄地失去维护。 这意味着,如果此代码中存在错误,或者发现其性能或界面缺乏(请参阅上面的“质量”),那么您将发现没有人可以熟练地改进它。

代码更改将在其他地方出现代码回归的非零概率,并且如果您的内部库没有经过单元测试,则这种回归将在相当长的一段时间内未被检测到。

我什至没有提到“我永远不会碰那个粘糊糊的代码”综合症,当有人试图纠正代码时发现他不明白为什么这样做(因为宏,奇怪的先决条件,等等..

结论

将两者结合起来,你会发现对于通用代码(即数组、字符串等),通过慢慢地从内部库迁移到STL库,在编写“转换函数”时会做得更好。 我认为

这种迁移是代码维护的一部分,并且您应该慢慢地(即使用新代码或重构时)尽可能使用 STL 而不是内部通用库。

The reasons I see are:

Quality of the code

The writers of the STL (either its interface, or the implementation for your compilers) are without doubts magnitudes better than the best developer in your company.

Their job is to make a usable STL, which means that every function/method/object is heavily tested anyway.

Maintainability of the code

With the turnover, some code can become slowly and stealthily unmaintained. Which means that if there is a bug in this code, or if its performance or interface are found lacking (see the "Quality" above), then you'll find no one to expertly improve it.

The code change will have a non-zero probability of a code regression elsewhere, and if your in-house library is not unit-tested, that this regression will go undetected for quite some time.

And I'm not even mentioning the "I WON'T ever touch that slimy code" syndrome when someone trying to correct the code just finds he doesn't understand why it was done this way (because of macros, strange pre-conditions, etc..

Conclusion

Combine the two, and you'll find that for generic code (i.e. arrays, strings, etc.), you'll go better by slowly migrating from in-house libraries to STL library, writting "converter functions" when needed.

I think this kind of migration is part of the maintenance of your code, and that you should slowly (i.e. with new code, or when refactoring), whenever possible, use STL instead of in-house generic libraries.

ˉ厌 2024-07-21 17:19:30

由于您已经有了实用程序类,因此无需使用 STL。 当您发现需要开始将 STL 集成到您的实用程序库中时,它很快就会成为一个可维护性问题。 在我看来,这将是生产力损失

也就是说,STL 可能提供许多实用程序库不提供的功能和实用程序。 (特别有用的是标头,您可以立即开始使用它,而不会出现遗留代码的许多问题。)如果您正在编写大量新代码,那么使用 STL(和 Boost,如果您可以)而不是编写自己的实用程序类和算法。 因此,这将是生产力的重大提高。

不过,我不知道有任何关于这个主题的研究。

Since you already have the utility classes, there's no need for using the STL. It will quickly become a maintainability problem as you find the need to begin integrating the STL into your utility libraries. IMO, it will be a productivity loss.

That said, the STL may offer a lot of features and utilities that your utility libraries don't provide. (Particularly useful is the <algorithms> header, which you can probably begin using immediately without many problems with legacy code.) If you're writing a lot of new code, it's far better to use the STL (and Boost, if you can) than to write your own utility classes and algorithms. As a result, it will be a major productivity gain.

I don't know of any studies on the topic, though.

最美不过初阳 2024-07-21 17:19:30

考虑一下您雇用新 C++ 程序员时的情况。 他/她更有可能拥有 STL 课程的经验还是您自己的课程的经验? 如果您开始切换到 STL,您可能会在变得富有成效之前节省大量时间。

Consider the situation when you hire a new C++ programmer. Is s/he more likely to have experience with STL classes or your own ones? You could be looking at huge savings in time before they become productive if you start to switch to the STL.

紫竹語嫣☆ 2024-07-21 17:19:30

目前,任何新雇用的员工都必须学习如何使用旧课程,这需要时间和金钱。 像其他人一样使用 STL 可以为您的公司节省资金并保持其在候选人中的吸引力。

Currently, any newly hired employee will have to learn how to use the old classes, and that costs time and money. Using STL like everyone else would save your company money and keep it attractive among the pool of candidates.

九厘米的零° 2024-07-21 17:19:30

不幸的是,我认为没有办法证明批量替换这些自定义类是合理的。 如果可能的话,一次用一个类的 STL 组件替换它们。

这是一项维护和保养工作。 可读性问题与任何事情一样重要。 (1) 使用 STL 可以帮助维护人员一目了然地理解代码,而不需要学习自定义实现的方法。 (2) STL 有很好的文档记录并且易于理解 - 您的自定义类怎么样? (3) STL经过严格审查。 (4) STL自带渐近运行时上& 下限。

祝你好运。

I don't think there is a way to justify replacing these custom classes wholesale, unfortunately. If possible, replace them with STL components a class at at time.

This is a maintenance & readability issue as much as anything. (1) Using STL helps maintainers understand the code at a glance, versus needeing to learn their way around custom implementations. (2) The STL is WELL documented and well understood - what about your custom classes? (3) The STL is well vetted. (4) The STL comes with asymptotic runtime upper & lower bounds.

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文