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++ 标准库 - 我应该什么时候使用它,什么时候不应该使用它?


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01