Live data from Hacker News

Why I don't spend time with Modern C++ anymore

linkedin.com

251–260 of 264 posts

Re: Why I don't spend time with Modern C++ anymore

#251

Earlier quoted context omitted.

With the use of link-time optimization, most of the overhead of using pimpl idiom is removed. Both the outter wrapper functions as well as the implementation functions can be inlined, making the function calls effectively like a normal class implemented inside a header.

The heap allocation for the implementation won't be removed by LTO.

I'm inclined to agree that for objects that are going to be created and destroyed very often, especially in tight loops, PIMPL is not an ideal idiom. I wouldn't use it to generate fleeting effects in graphics, for example.

For objects that are used in setting up parts of a system and that will persist for long periods of time, maybe even the lifetime of the app, PIMPL is particularly well-suited for such classes. Classes that might manage networking, or encompass an entire part of app's running architecture, etc.

Re: Why I don't spend time with Modern C++ anymore

#253

Earlier quoted context omitted.

You should see the code that variadic templates replace.

Say more! I'd like to know what you mean.

Before variadic templates you couldn't define a function template taking an arbitrary number of arguments; what you could do is define N overloads up to a finite large N. This quickly becomes tedious and hard to maintain, so you either write an external generator script, or 'creatively' use the preprocessor. These solutions were also not much easier to maintain and of course would kill compilation times.

The worst part is that often these were forwarding functions, that is, they didn't do anything directly with their parameters, but simply forwarded them to some other function (this happen surprisingly often in highly generic code). To do forwarding correctly, you have to handle const and non const reference arguments properly, which means that N overloads are not enough and you need N*2^N (someone please check my math) overloads. As you can imagine, this was impractical for N > 3.

Variadic templates plus perfect forwarding via magic references make easy, practical and possible what was impractical before.

edit: spelling

Re: Why I don't spend time with Modern C++ anymore

#254
post #189

Earlier quoted context omitted.

> I don't see any logical impossibilities for one > language to solve all problems There are no logical impossibilities in constructing a vehicle that can serve as a passenger vehicle, dump truck, submarine, and airplane, but tensions in design will very likely result in a compromise that is more complicated, more expensive, and less capable than a dedicated solution. Not only that, but your vehicle will be just as i…

> a passenger vehicle, dump truck, submarine, and airplane The problem with using metaphors to make your argument is we generally have to argue about whether the metaphor is even appropriate enough that the conclusions apply to the original topic... It's simpler just to argue the topic. Within a huge class of problems, I don't need to get a new computer to solve each new thing that comes up. That's a very general too…

  > The problem with using metaphors
Then ignore the metaphor and focus on the longer paragraph that succeeds it. :P

  > I don't need to get a new computer to solve each new 
  > thing that comes up
Except that, in practice, you do. I have a smartphone in my pocket, a laptop in my bag, a desktop in my office, and two personal servers in the cloud. Just because two computers are both effectively Turing machines does not automatically invalidate the importance of form factors, power draw, integrated peripherals, physical location, and other practical differences. This also ignores the existence of domains that actually demand dedicated hardware, like supercomputing. We are never going to live in a world where microcontrollers are just as capable at running weather simulations as the TOP500, because the economics don't pan out. So no, you're right, it is not logically impossible to construct a language that is capable of performing all imaginable tasks, though that's not something that I've ever disputed. Rather than being logically impossible, it's merely economically infeasible. :P

Re: Why I don't spend time with Modern C++ anymore

#255
post #236

Earlier quoted context omitted.

> Liquidity means the price is stable not that trades will go through.* Stable prices prevent HFT traders from making money. No, liquidity means there's limit orders sitting on the market. That is quite literally all liquidity is. > Stable prices prevent HFT traders from making money. No they don't, stable prices are good for market makers as it reduces the risk of flipping the spread. You can sit there all day long…

> market makers ... without prices moving a lick If orders are going though at different prices that's volatility, even if it's just bid ask spread. Reducing bid - ask spread is how HFT traders are supposed to reduce volatility in the first place. Trade at 10.10, 10.00, 10.10 is price motion even if the trades where buy 10.10, sell 10.00 buy 10.00 because a party needs to sit on the other side of the transaction so a…

If the ask doesn't move, and the bid doesn't move, orders will happen at both prices due to market orders from both bears and bulls; if you'd like to call that "price moving" you're free too, but I won't. If you were staring at a chart you'd see nothing happening at all because charts don't chart orders, they chart the bid and ask or some middle between them. Regardless, you get my point, the bid and ask do not have to move at all for a market maker to make money, they would in fact prefer the safety of no directional movement.

Re: Why I don't spend time with Modern C++ anymore

#256
I never programmed HFT software, but I agree with the criticism of the modern C++.

It’s bad the author hasn’t defined what exactly’s “modern” is. I saw some comments compared boost with C++/14. I think boost is also modern. Even Alexandrescu’s Loki is also modern, despite the book was published in 2001.

I think that modern stuff was introduced in C++ because in end 90s-start 2000s there was expectation C++ will remain dominant for some time. There was desire to bring higher-level features to the language, to make it easier to learn and safer to use — even at the cost of performance.

People didn’t expect C++ will lose its market that fast: very few people now use C++ for web apps or rich GUI. However, due to the inertia and backward compatibility, the features remain in the language.

Personally, I’m happy with C++.

C++ is excellent for system programming, also for anything CPU bound. For those you barely need those modern features, and fortunately, they’re completely optional: if you don’t like them, don’t use them.

But if you do need higher-level language for less performance-critical parts of the project, I find it better to use another higher-level language and integrate it with that C++ library. Depending on the platform, such higher-level language could be C#, Lua, Python, or anything else that works for you.

Re: Why I don't spend time with Modern C++ anymore

#257

20 year C++ programmer here. I work on multithreaded server code. Stopped using modern C++ features 5 years ago. I'd compare my use of C++ to be roughly equivalent to the use of C++ in the NodeJS project or the V8 project. I'm not a user of Boost. I have to agree with the author of the article. It takes longer to train developers to write idiosyncratic modern C++ code and compilation times explodes. Compiler support…

15 years here.

I'm mostly in MS ecosystem, so I don't have issues with C++ compiler support. But I totally agree with the rest of your comment.

Re: Why I don't spend time with Modern C++ anymore

#258
I was once a C++ programmer but migrated first to Java, when I thought it was better designed and more convenient, and then to Python when I wanted less verbosity while having greater freedom to choose between a procedural style or OO.

C++ may still be an ideal choice in some problem spaces but I think the number and size of them has shrunk as more and better alternate choices have appeared and ate away at the C++ share.

Re: Why I don't spend time with Modern C++ anymore

#259
post #254

Earlier quoted context omitted.

> a passenger vehicle, dump truck, submarine, and airplane The problem with using metaphors to make your argument is we generally have to argue about whether the metaphor is even appropriate enough that the conclusions apply to the original topic... It's simpler just to argue the topic. Within a huge class of problems, I don't need to get a new computer to solve each new thing that comes up. That's a very general too…

> The problem with using metaphors Then ignore the metaphor and focus on the longer paragraph that succeeds it. :P > I don't need to get a new computer to solve each new > thing that comes up Except that, in practice, you do. I have a smartphone in my pocket, a laptop in my bag, a desktop in my office, and two personal servers in the cloud. Just because two computers are both effectively Turing machines does not auto…

> Then ignore the metaphor and focus on the longer paragraph that succeeds it. :P

Your second paragraph had a bunch of economic pseudo-theory about what sells... Maybe that explains why we don't have a good general purpose programming language, but it said little about whether there could be one.

Re: Why I don't spend time with Modern C++ anymore

#260
post #59

Earlier quoted context omitted.

Not milliseconds. Nanoseconds. Competitive tick-to-trade times are on the order of 1000ns or less.

How do you tune the machine for that type of latency? User space drivers? Could you elaborate? Not having to go beyond L1 cache doesn't mean much if it takes a few milliseconds to get that trade out of the network card and on to the wire right?

FPGAs
Post reply on HN