Live data from Hacker News

Does C++ still deserve a bad rap?

nibblestew.blogspot.com

251–260 of 310 posts

Re: Does C++ still deserve a bad rap?

#251
post #212

Earlier quoted context omitted.

From memory, a thing i've implemented in C++ that its basically impossible in almost any other languages (with few exceptions). Represent a data table in memory where the columns are from different types, where the data is backed by a arena allocator and represented contiguously in memory. Of course you can do a data table representation in almost any language, but once you benchmark the implementations, the language…

Sounds like Rust should handle this case just fine?

Yes, Rust is one of those languages now. (C, C++ and the newcomers Rust and Zig)

Re: Does C++ still deserve a bad rap?

#252

Earlier quoted context omitted.

Is there any language where string handling doesn't suck? (No script languages please, because they cheat by implementing the hard things on C or C++) From memory the less horrible experience i had was with Go, but there's help for the slices on the runtime which let the difficult parts hidden and also the batteries-included std library, which is one of the most well designed standard libraries out there. Buffer mana…

C# and Python... "a, b".Split(", ") // C# "a, b".split(", ") # Python

In Rust:

    "a, b".split(", ")

Re: Does C++ still deserve a bad rap?

#253
post #201

Earlier quoted context omitted.

To be fair, C++'s standard I/O library is really bad. There is probably an almost universal consensus in the C++ world that the locale library is the worst standard library, immediately followed by iostreams. For small programs that's annoying, although using libc IO is usually fine for them. However, C++ is probably one of the top 3 languages for developing large applications (Java would also be there, not sure whic…

In terms of large projects C++’s role is very much shrinking. C++’s last major strength is being cross platform, but new platforms keep excluding it. You can’t program on iOS or client side websites with it. Microsoft actively discourages using C++ on Windows, and C# took over for large projects. Essentially C++ and the modern ideas about computer security are at war.

Modern C++ is actually encouraged on Windows with Microsoft making standards compliant and supported frameworks like C++/WinRT for WinUI3.

https://docs.microsoft.com/en-us/windows/apps/winui/winui3/x...

Re: Does C++ still deserve a bad rap?

#254

Like every programming language out there, C++ is a tool. And like every tool out there it has its uses. There isn't any point of using C++ to count words in a text file. Any high-level language like Python will beat you to it. However, there's one thing you can do in C++ and not in Python or JavaScript or PHP: fully control the memory layout of your data. While you don't need it in most of the cases, it becomes a ki…

fyi, you can read mmap files in Python too:

  import mmap # Unix, Windows

  with open('c_structs.bin', 'rb') as file, mmap.mmap(file.fileno(), 0, access=mmap.ACCESS_COPY)) as buf: 
        result = (YourStruct * 3).from_buffer(buf) # without copying
https://stackoverflow.com/questions/17244488/reading-struct-...

Re: Does C++ still deserve a bad rap?

#255

I still love C++ but rarely code in it any more. One interesting thing is that the whole modern approach to immutable data structures seems so wasteful to me now. C++ you literally take strings and overwrite characters, where now people duplicate lists of records just to stay clean. Once you have the discipline you need in C++ to make mutable data structures work its a hugely efficient place to be. However I sleep mu…

> C++ you literally take strings and overwrite characters, where now people duplicate lists of records just to stay clean.

When you're dealing with UTF-8, you can't overwrite your buffer in the general case because changing case can change the encoded length of the characters.

Re: Does C++ still deserve a bad rap?

#256

As someone who writes <5 commits of C++ per year, it is very frustrating. I can’t get through a code review without reviewers referencing at least 2 blog posts about proper style for modern C++. I’m sure if I were an expert who used it every day I could remember all the gotchas and best practices, but it sure is tedious to deal with occasionally. Too many foot guns and conventions, not enough constraints in the langu…

Thankfully, one can stick to the C++ Core Guidelines now. Abseil also has some good recommendations. The rest is just bikeshedding.

Re: Does C++ still deserve a bad rap?

#257

My beef with C++ is with its dependency (non)management. For almost every modern language, you can easily build and run code - pull code from repo, run the included script or standard command to get the dependencies and build it, bam, you're done without needing to know much about that language. With C++ it seems like half of the time pulling someone else's old project from github and running make (or whatever the au…

vcpkg/conan solves this headache quite well now.

Re: Does C++ still deserve a bad rap?

#258
post #201

Earlier quoted context omitted.

To be fair, C++'s standard I/O library is really bad. There is probably an almost universal consensus in the C++ world that the locale library is the worst standard library, immediately followed by iostreams. For small programs that's annoying, although using libc IO is usually fine for them. However, C++ is probably one of the top 3 languages for developing large applications (Java would also be there, not sure whic…

In terms of large projects C++’s role is very much shrinking. C++’s last major strength is being cross platform, but new platforms keep excluding it. You can’t program on iOS or client side websites with it. Microsoft actively discourages using C++ on Windows, and C# took over for large projects. Essentially C++ and the modern ideas about computer security are at war.

For data-intensive applications, which are only increasing, C++ is the only game in town. State-of-the-art architectures typically rely on schedule-based safety models that are not productively expressible within Rust's ownership-based safety model, and the performance characteristics of working within these respective safety models is not comparable. There aren't many alternatives when a GC language is a non-starter due to the adverse impact of a GC on throughput. C++ is winning for data-intensive apps not because it is great (it isn't) but because there isn't a practical alternative.

I've seen Rust being used for the layer above C++, where it doesn't have to deal with I/O, scheduling, etc that don't play well with Rust but you still want the throughput/latency and memory safety.

Re: Does C++ still deserve a bad rap?

#260
post #119
post #5

I don't think C++ ever really had a bad rap except among ideologues and evangelists of other languages. In my experience, people like this are very rare in the real world outside of maybe Rust conferences.

Equally, a lot of people just don't know any different. How would you know C++ isn't optimal if you've never tried or thought about anything else. That and the sunk-cost of learning C++ is large.

You can't get a degree without being exposed to a number of lecturer's language-of-choice. I'd be shocked to find someone who had only used c++
Post reply on HN