Hacker News new | ask | show | jobs
by feylikurds 3736 days ago
Dear God, now I remember why I do not program in C++ anymore (Go and C# all the way!). That pre-11 code looked awful. If networking was nicer, I might actually start considering recoding some of my projects in C++.
2 comments

If you have £40 or so, and a few evenings free, get the C++11 version of the Stroustrup programming language book and see what's changed. Modern C++ looks entirely different to older C++. Templates still a bit scary, so learn them or ignore them.
Yes, but are there still tons of boilerplate? Or is there a 11/14/17 library that incredibly decreases the amount of code needed? For example a HTTP listener with routing?
It's hard to say what he was trying to accomplish, but he probably could have written something like this.

    auto index = std::distance (begin(replicas),
                   std::find(begin(replicas), end(replicas), my_ip));
    return (replicas.size() == index ? -1 : index);
That's a bit harder to read isn't it? I think finding the location in first line and using distance in the ternary operator makes it more readable.
Like this?

    auto it = std::find(begin(replicas), end(replicas), my_ip);
    return (end(replicas) == it ? -1 : std::distance(begin(replicas), it));
Yeah, i'll go with that.
Yeah that's what I was thinking.