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++ 标准库 - 我应该什么时候使用它,什么时候不应该使用它?
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
