TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The hidden cost of C++ (2009)

41 点作者 fogus超过 12 年前

13 条评论

nostrademons超过 12 年前
With modern optimizing compilers and CPU architectures, you can't really predict the cost of code merely by looking at it anyways. Not in any language.<p>Will that function call be inlined? Does it have side-effects? Are the arguments constant, so that it might even be evaluated at compile-time? Can it be hoisted out of a loop? Do its pointer args alias, preventing many of these operations? Is it big enough to blow the cache, or will it all fit in L1 and benefit from really fast memory accesses? Can branch-prediction operate effectively on its loops, or does it have an unpredictable pattern that will flush the pipeline many times?<p>I've heard that the best way to get your program to run fast is to get it into a compiler benchmark suite, so that compiler-writers account for it when writing optimizations. Failing that, it's all about profiling so you can measure the <i>actual</i> cost rather than relying on what you think you know about the programming language.
评论 #4539843 未加载
评论 #4540229 未加载
16s超过 12 年前
I use C++ daily for systems level programming and I love it. If I could only have one programming language it would be C++. I can write anything in it and I actually enjoy doing so. Maybe I'm weird or something, but I know a lot of other guys who feel this way too.<p>And, I know some other guys who do hard core embedded C programming and they are migrating to C++. They love it compared to C and can't wait until every line of their C code has been reimplemented in C++.<p>C++ will be around for decades to come and many folks actually enjoy writing it, they just don't advertise that fact.
评论 #4540784 未加载
评论 #4540250 未加载
评论 #4540321 未加载
eridius超过 12 年前
I'm disappointed. I expected this to be a post along the lines of Ridiculous Fish's two posts on C++ features that you pay for even if you don't use:<p>1. <a href="http://ridiculousfish.com/blog/posts/i-didnt-order-that-so-why-is-it-on-my-bill-episode-1.html" rel="nofollow">http://ridiculousfish.com/blog/posts/i-didnt-order-that-so-w...</a><p>2. <a href="http://ridiculousfish.com/blog/posts/i-didnt-order-that-so-why-is-it-on-my-bill-episode-2.html" rel="nofollow">http://ridiculousfish.com/blog/posts/i-didnt-order-that-so-w...</a><p>Thankfully one of C++11's requirements was to not introduce any new functionality that had penalties even if you aren't using it. Too bad that wasn't a requirement for the original design of the language.
评论 #4540730 未加载
评论 #4540179 未加载
评论 #4540127 未加载
BudVVeezer超过 12 年前
Awesome! Another "<i>I</i> don't understand writing good code in language X, thus <i>that language</i> has 'hidden' deficiencies." post.<p>You can write non-performant code in any language you'd like, and obscure it in non-trivial ways. That's not the fault of the language.
评论 #4539769 未加载
评论 #4539789 未加载
评论 #4539507 未加载
评论 #4539504 未加载
评论 #4539515 未加载
dude_abides超过 12 年前
The same underlying point can be made in such contrasting styles: Linus ( <a href="http://harmful.cat-v.org/software/c++/linus" rel="nofollow">http://harmful.cat-v.org/software/c++/linus</a> ) vs the OP.
评论 #4539499 未加载
jon6超过 12 年前
I don't necessarily disagree with this assessment but you can easily create functionality in C that requires looking at multiple source files to understand whats going on.<p><pre><code> x = foo(bar(), baz()); </code></pre> Now you have to look at the definitions for bar and baz to understand the cost of this line.<p>I guess this is the trade-off with using a high level language. Expressivity vs transparency.
评论 #4539478 未加载
kqr2超过 12 年前
Note: post is from 2009.<p>She also has a followup where she explores the "pressure points" of writing games in C++:<p><a href="http://www.rachelslabnotes.com/2009/11/there-are-never-enough-render-engines/" rel="nofollow">http://www.rachelslabnotes.com/2009/11/there-are-never-enoug...</a>
VikingCoder超过 12 年前
The days when you can reason about performance by looking at function signatures are, in my opinion, long gone.<p>I can count on one hand the number of times that I thought that changing the function signature of a few methods was going to impact whole application performance. Every time, it was in a low-level function that was called all over the place. Or, more to the point, I dug into function signatures when evidence pointed me there.<p>I can't even begin to list all of the other problems I worry about that actually do impact whole application performance on a regular basis.
cjensen超过 12 年前
Slapping an "explicit" modifier on all your constructors eliminates what the author is complaining about.
评论 #4540018 未加载
halayli超过 12 年前
Abstraction in general comes at a cost.
评论 #4539546 未加载
评论 #4539549 未加载
malkia超过 12 年前
in 1999 I was a total C++ dude. I had to work that year on a port of metal gear solid for PC. I was surprised to see such well written C code by the konami developers, with nice oo system that had certain tcl element to it. There were only comments in japanese but that did not stopped us from understanding how it worked.
评论 #4540168 未加载
评论 #4540291 未加载
lelele超过 12 年前
For me, the hidden cost of C++ was the mental overhead of programming in it. I had to be constantly alert about the many many ramifications of almost every line I wrote.
LiveTheDream超过 12 年前
Can we get a [2009] in the headline?