logoalt Hacker News

canpantoday at 10:54 AM3 repliesview on HN

String views were a solid addition to C++. Still underutilized. It does not matter which language you are using when you make thousands of tiny memory allocations during parsing. https://en.cppreference.com/w/cpp/string/basic_string_view.h...


Replies

VorpalWaytoday at 11:29 AM

The issue with retrofitting things to an existing well established language is that those new features will likely be underutilized. Especially in other existing parts of the standard library, since changing those would break backwards compatibly. std::optional is another example of this, which is not used much in the c++ standard library, but would be much more useful if used across the board.

Contrast this with Rust, which had the benefit of being developed several decades later. Here Option and str (string views) were in the standard library from the beginning, and every library and application uses them as fundamental vocabulary types. Combined with good support for chaining and working with these types (e.g. Option has map() to replace the content if it exists and just pass it along if None).

Retrofitting is hard, and I have no doubt there will be new ideas that can't really be retrofitted well into Rust in another decade or two as well. Hopefully at that point something new will come along that learned from the mistakes of the past.

show 1 reply
pjc50today at 11:26 AM

C# gained similar benefits with Span<>/ReadOnlySpan<>. Essential for any kind of fast parser.

show 1 reply
groundzeros2015today at 12:53 PM

In C you have char*

show 3 replies