C ++标准库 - 当我应该使用它,什么时候不应该吗? [英] C++ standard library - when should I use it and when shouldn't I?

查看:133
本文介绍了C ++标准库 - 当我应该使用它,什么时候不应该吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道多久人们实际使用多少的标准的C ++库,特别是在&LT的东西;算法> <数字&GT ; 头。教科书似乎推荐他们,但我还没有看到任何人使用在所有的我已经通过筛选各种项目(巧合?),并亲自它似乎更容易只是每次写适当的简单的算法我自己,而不是背诵或请教每次提到这些报头。我只是懒惰或固执?有没有实际使用这些库时,性能提升等?

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?

谢谢

研究

推荐答案

这是可能你懒惰或固执。就个人而言,我使用他们生产code所有的时间。

It's possible you're being lazy or stubborn. Personally, I use them all the time in production code.

我不这样做,是看中了,因为我喜欢写我不这样做太空时代的code。相反,我这样做是因为我是一个偏执的程序员,我知道,生产环境是充满敌意的地方,这将毁坏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.

我这样做是因为我生活的座右铭,最好的code,是code,你从来不写。这需要时间来学习如何使用STL和放大器;标准库的有效的,但一旦你做,你会发现,它可以用来使什么现在是1000行code成为可能100这100个可能需要长达写的原来1000,但有较少的故障点。在code可以是更强大的,如果你站在别人的肩膀上。

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 ++标准库 - 当我应该使用它,什么时候不应该吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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