commit | f7bb3e865b0d6ba8bbc79d046282e4fd4526ac34 | [log] [tgz] |
---|---|---|
author | Jiyong Park <jiyong@google.com> | Fri Dec 10 22:46:25 2021 +0900 |
committer | Jiyong Park <jiyong@google.com> | Wed Dec 15 14:00:54 2021 +0900 |
tree | d21fa905bfd9c6a04b633aca1ce5c78a22c5ea59 | |
parent | a0eec0eea8f9163f2eacee8ca702fe737f6c5a0e [diff] |
android::base::Result supports cutsom error code The error type for android::base::Result<T> was fixed to ResultError which consists of an errno and an error message. It wasn't useful in places where custom error reporting mechanisms like status_t are used. In this CL, we attempt to address this issue by adding a new type parameter E which is for error code. i.e. Result<T, E>. For compatibility, E defaults to int. When such a custom error code type is used, user should provide a printer class that is reponsible for converting the error code into a corresponding human readable string. Specifically, the printer class should provide a static method `const char* print(const E&)`. Bug: 209929099 Test: atest libase_test Change-Id: Iedd17414fb156ab3548ed937d9ed45f941f446ce
This library is a collection of convenience functions to make common tasks easier and less error-prone.
In this context, "error-prone" covers both "hard to do correctly" and "hard to do with good performance", but as a general purpose library, libbase's primary focus is on making it easier to do things easily and correctly when a compromise has to be made between "simplest API" on the one hand and "fastest implementation" on the other. Though obviously the ideal is to have both.
The intention is to cover the 80% use cases, not be all things to all users.
If you have a routine that's really useful in your project, congratulations. But that doesn't mean it should be here rather than just in your project.
The question for libbase is "should everyone be doing this?"/"does this make everyone's code cleaner/safer?". Historically we've considered the bar for inclusion to be "are there at least three unrelated projects that would be cleaned up by doing so".
If your routine is actually something from a future C++ standard (that isn't yet in libc++), or it's widely used in another library, that helps show that there's precedent. Being able to say "so-and-so has used this API for n years" is a good way to reduce concerns about API choices.
Unlike most Android code, code in libbase has to build for Mac and Windows too.
Code here is also expected to have good test coverage.
By its nature, it's difficult to change libbase API. It's often best to start using your routine just in your project, and let it "graduate" after you're certain that the API is solid.