C++ standard library - when should I use it and when shouldn#39;t I?(C++ 标准库 - 我应该什么时候使用它,什么时候不应该使用它?)
问题描述
我想知道人们实际使用大量标准 c++ 库的频率,尤其是 和
I was wondering how often people actually use much of the standard c++ library, particularly the stuff in the <algorithm>
and <numeric>
headers. The text books seem to recommend them, but I haven't seen any of them used at all in various projects I've sifted through (coincidence?) and personally it seems easier to just write appropriate simple algorithms myself each time rather than memorize or consult a reference to these headers each time. Am just being lazy or stubborn? Is there actually performance gains etc when using these libraries?
谢谢,
R
推荐答案
你可能是懒惰或固执.就个人而言,我一直在生产代码中使用它们.
It's possible you're being lazy or stubborn. Personally, I use them all the time in production code.
我这样做并不是为了炫耀,也不是因为我喜欢编写太空时代代码".相反,我这样做是因为我是一个偏执的程序员,而且我知道生产环境是充满敌意的地方,如果有机会的话,它们会破坏代码并使我的程序变成一堆冒烟的无价值字节.
I don't do this to be fancy, and I don't do this because I like writing "space-age code." Rather, I do this because I am a paranoid programmer, and I know that production environments are hostile places that will mutilate code and reduce my programs to smoking piles of worthless bytes, if given a chance.
我这样做是因为我的座右铭是:最好的代码,是你永远不会写的代码."学习如何使用 STL &Std Lib 有效,但是一旦你这样做了,你会发现它可以被使用,所以现在的 1000 行代码可能变成了 100 行.这 100 行可能需要与原始 1000 行一样长的时间来编写,但故障点较少.如果你站在别人的肩膀上,代码会更健壮.
I do this because I live by the motto, "The best code, is the code you never write." It takes time to learn how to use the STL & Std Lib effectively, but once you do you'll find that it can be used so that what now is 1000 lines of code becomes perhaps 100. Those 100 might take as long to write as the original 1000, but there are fewer failure points. The code can be more robust, if you stand on the shoulders of others.
这篇关于C++ 标准库 - 我应该什么时候使用它,什么时候不应该使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 标准库 - 我应该什么时候使用它,什么时候不应该使用它?
基础教程推荐
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01