Hacker News new | comments | show | ask | jobs | submit login
C++ Tips of the Week (abseil.io)
212 points by fauigerzigerk 8 months ago | hide | past | web | favorite | 34 comments

For those interested in such insightful tech reads, I run https://discoverdev.io - a daily curated list of top 8 to 10 engineering blog posts!

Published every weekday!

Use string_view, but beware of use-after-free bugs like https://github.com/isocpp/CppCoreGuidelines/issues/1038

Think of string_view as a non-owning pointer to a known-size array. If the array is moved or destroyed, then string_view is left dangling... just like a pointer.

Naming of the title reminds me of the best C book I've read, "Expert C Programming: Deep C Secret" by Peter Van Der Linden.


In a similar vein, we published a „little book of Python anti patterns“ a while back, maybe some people find it useful:


Seems that only four of the tips are available?

They're doing one a week, starting 4 weeks ago.

On average it seems, because it took a months wait for three to be released at once.

Hopefully whatever stopped the project has been resolved and they’ll be consistent now.

They should reindex their archive of tips. I was baffled by the jump from tip 1 to 55 to 77.

Edit: the indexing is explained in a note on the site.

The index is related to when the tips were published internally at Google, and are not re-indexed for the sake of those who have already seen them

If you look at the paragraph above them, last in the article they explain why it is.

This is specifically addressed in the article at the bottom as a note.

something similar was initiated by herb-sutter as well in his 'guru of the week' (gotw) columns. which then became books in their own right aka 'exceptional c++' series.

are these tips more 'modernish' ?

Tip #1 covers a feature found in C++17, so I'd say yes.

Tip #1 appears on the surface to be about C++17's std::string_view, but many shops had something similar to string_view for a decade or more before C++ made it official. The tips are not presented in their original form; edits have been made (as per the linked page). I think Google had something like string_view by 2009 at the latest, using C++03 compilers.

Yeah, discussing the origins of string_view is like talking about who invented base-two numbering. :-)

Yes. It is a small step from the well-worn convention to pass each char* around with its length.

> Yes. It is a small step from the well-worn convention to pass each char* around with its length.

kind of surprising to note that implicit 'string_view' conversions are now regarded as a good thing?

on a side note, the language is _complicated_, and shows no signs of stopping ! 3 articles on move/copy ctor's and only one that applies to programming in general.

Links to illustrate:


This proposal references Google and LLVM implementations:


Looks like the LLVM implementation goes back to at least 2009:


>I think Google had something like string_view by 2009 at the latest, using C++03 compilers.

Yeah, StringPiece


And they also claim string_views can be constructed from a std::string. That's true of their implementation and it's true of the TS string_view but it was removed from the c++17 string_view.

EASTL had it at least as early as 2005.

Both series have been created over many years, so I'm not sure which one is more modern. Herb Sutter says that all GotW articles are being revised to reflect changes in C++14.

Herb Sutter's recent tips are more modern (and the backlog is being updated).

Scott Meyers' Effective Modern C++ is a great successor to his Effective C++ book which spawned the whole "Effective *" snowclone books and covers C++14, though not 17, of course.

Actually, this blog post's content looks like a watered-down version of a tip from either or both of the above authors, though I'm too lazy to chase down a verification.

I've failed the first test: how do I get a list of all "tips"?

I think they only made those 4 public for now.

shame, was going to binge read them

Here is my personal advice: whatever code you write, make sure you can grab it and run leaving no trace behind.

> We’ve decided to expose most of these tips to the Abseil development community, and the C++ community at large. Over the coming months, we’ll be posting new tips as we review and refine them for publication. Not all the entries we’ve written are relevant to the outside world; some were specific to our internal tools and abstractions, and some have become obsolete as the language has changed.

I followed a few links to Abseil:

> Consisting of the foundational C++ and Python code at Google, Abseil includes libraries that will grow to underpin other Google-backed open source projects like gRPC, Protobuf and TensorFlow.

This library already seems like it is suffering from scope-creep. Tensorflow, gRPC, and Protobuf are hardly related to improving the C++ standard. Why are these even in the same library at all?

They're not. They will be using Abseil.

Google needs to open source its core C++ libraries if it is going to open source the projects that depend on the core libraries.

“Underpin” e.g. those libraries will use Abseil as a common base.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact