I'd like to simplify ppapi/cpp files by getting rid some some
boilerplate that I'm not convinced is necessary. Details are below.
In many interfaces, function implementations are identical across versions.
See ppapi/thunk/ppb_file_io_thunk.cc for an example. All of the functions
pointed to in the interface are the same, except 1.1 adds "ReadToArray".
However, ppapi/cpp/file_io.cc has code that looks like this:
int32_t FileIO::Query(PP_FileInfo* result_buf,
const CompletionCallback& cc) {
if (has_interface<PPB_FileIO_1_1>()) {
return get_interface<PPB_FileIO_1_1>()->Query(
pp_resource(), result_buf, cc.pp_completion_callback());
} else if (has_interface<PPB_FileIO_1_0>()) {
return get_interface<PPB_FileIO_1_0>()->Query(
pp_resource(), result_buf, cc.pp_completion_callback());
}
return cc.MayForce(PP_ERROR_NOINTERFACE);
}
This approach has some advantages:
* If we ever remove version 1.0 of the interface, things will still work.
This seems extremely unlikely for stable APIs, however.
* Using a mock of the PPB_FileIO_1_1 interface is very straightforward in
tests.
* We will consistently use the same version of the interface for every call
on a system. Yuzhu has voiced a concern that a Create() call at version 1.0
could be incompatible with (say) a function call at version 1.1. I don't·
know if we have concrete cases where this could happen.
And some disadvantages:
* There's a lot of boilerplate, and the result is that the same code ends up
being executed.
* It makes the code harder to read by making there appear to be multiple
implementations when that is not the case.
I don't think the advantages are worth the loss in readability, but
I'd like to hear what everyone thinks.
The idea that using the older version is simpler has come up a number of times. I guess it depends on what you mean by "simple".I find having a bunch of identical boilerplate everywhere consistently mentally simpler for me than inconsistent boilerplate, even if it's a bit longer and more tedious.
When we last discussed this I started out strongly in favour of simplifying, but a couple of good points were raised, most significantly around hampering interface deprecation.
FWIW, I think it'd be worth having macros, if possible, so we can maintain the current semantics but reduce boilerplate.
On Thu, Mar 28, 2013 at 3:09 PM, Wez <w...@chromium.org> wrote:
When we last discussed this I started out strongly in favour of simplifying, but a couple of good points were raised, most significantly around hampering interface deprecation.Yeah, I'm starting to feel the same way. Now that I realize doing it the shorter way makes it virtually impossible to deprecate an interface (e.g. PPB_FileIO_1_0), I'm more interested in the verbose fallback code. That said, it's not enough for me to feel comfortable deprecating any stable interface.FWIW, I think it'd be worth having macros, if possible, so we can maintain the current semantics but reduce boilerplate.I'd be open to seeing what it looks like. I started typing up a proposal in my original e-mail, but I'm not really sure if it's better. Makes it less mistake-prone, but not necessarily more readable.