Live data from Hacker News

Modernize your C++ code

jarchitect.com

31–34 of 34 posts

Re: Modernize your C++ code

#31

> Pass-By-Value: Detect const-ref parameters that would benefit from using the pass-by-value idiom. I don't get why to make this change and the justification (after following 2 links deep: Want Speed? Pass by Value) is a 404. Move constructors are great and it's awesome that a bunch of what used to be copy-constructor overuse in C++03 can now be done without deep copies in C++11. But I don't understand why explicitly…

My understanding is simply that many programmers have a habit of passing parameters as const references. If they want a copy of the parameter, they make that copy by hand. In fact, on Thursday, I found a function in the code I work on that does exactly this.

That prevents some compiler optimizations ( http://stlab.adobe.com/wiki/images/8/85/2008_06_26_classes_t... ), but those optimizations predate C++11, so I don't know why the advice is in this article. In any case, if you want a function to operate in a copy of a parameter, consider passing that parameter by value instead of passing it by const reference and then making a copy. Note, this is not advice to start making unnecessary copies; instead it's advice that if you need a copy of something, rely on the compiler to make that copy for you.

Re: Modernize your C++ code

#32

> Pass-By-Value: Detect const-ref parameters that would benefit from using the pass-by-value idiom. I don't get why to make this change and the justification (after following 2 links deep: Want Speed? Pass by Value) is a 404. Move constructors are great and it's awesome that a bunch of what used to be copy-constructor overuse in C++03 can now be done without deep copies in C++11. But I don't understand why explicitly…

This post explains when you should and shouldn't use it: https://juanchopanzacpp.wordpress.com/2014/05/11/want-speed-...

Re: Modernize your C++ code

#33
post #6

Earlier quoted context omitted.

How's your astroturfing day going so far?

I don't understand this reaction. If the thread had several posts from green users like these, maybe it would be appropriate to jump to this conclusion. A more charitable explanation that I also consider to be likely is that jbHawk was a long-time HN reader who simply never felt the need to have an account until this post about a pretty neat tool which inspired them to comment.

Im such a user. Sometimes I feel the urge to comment, but it happens so rarely that I won't recall my username or password. So I probably have 20 accounts on HN and 40 on Reddit, each with just a few posts.

Re: Modernize your C++ code

#34

Earlier quoted context omitted.

This is interesting because it raises the whole meta-question of -- could you have developed feature X faster if you'd already done refactor Y? In my experience the answer is usually "yes", but if you have a mostly-moribund code base already, then it's usually "no". Hey, reasonable people can disagree! :) EDIT: "You should not use it because you read about it on the Internet, or because it's the new hotness.". That's…

I find that if I look at features I write and ask "Could I have developed feature X faster if I had already done refactor Y?", then the answer is usually "yes" as well. The problem is that this isn't the question you're actually faced with when you make a decision (it is the question you're faced with when you're an engineer that actually has to write the code, which is why engineers and management usually differ on…

The way you went meta in this comment: I wish I could find more kinds of comments like this on the internet. This I can refer to in 5 years.
Post reply on HN