1*d9f75844SAndroid Build Coastguard Worker# How to write code in the `api/` directory 2*d9f75844SAndroid Build Coastguard Worker 3*d9f75844SAndroid Build Coastguard WorkerMostly, just follow the regular [style guide](../g3doc/style-guide.md), but: 4*d9f75844SAndroid Build Coastguard Worker 5*d9f75844SAndroid Build Coastguard Worker* Note that `api/` code is not exempt from the “`.h` and `.cc` files come in 6*d9f75844SAndroid Build Coastguard Worker pairs” rule, so if you declare something in `api/path/to/foo.h`, it should be 7*d9f75844SAndroid Build Coastguard Worker defined in `api/path/to/foo.cc`. 8*d9f75844SAndroid Build Coastguard Worker* Headers in `api/` should, if possible, not `#include` headers outside `api/`. 9*d9f75844SAndroid Build Coastguard Worker It’s not always possible to avoid this, but be aware that it adds to a small 10*d9f75844SAndroid Build Coastguard Worker mountain of technical debt that we’re trying to shrink. 11*d9f75844SAndroid Build Coastguard Worker* `.cc` files in `api/`, on the other hand, are free to `#include` headers 12*d9f75844SAndroid Build Coastguard Worker outside `api/`. 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard WorkerThat is, the preferred way for `api/` code to access non-`api/` code is to call 15*d9f75844SAndroid Build Coastguard Workerit from a `.cc` file, so that users of our API headers won’t transitively 16*d9f75844SAndroid Build Coastguard Worker`#include` non-public headers. 17*d9f75844SAndroid Build Coastguard Worker 18*d9f75844SAndroid Build Coastguard WorkerFor headers in `api/` that need to refer to non-public types, forward 19*d9f75844SAndroid Build Coastguard Workerdeclarations are often a lesser evil than including non-public header files. The 20*d9f75844SAndroid Build Coastguard Workerusual [rules](../g3doc/style-guide.md#forward-declarations) still apply, though. 21*d9f75844SAndroid Build Coastguard Worker 22*d9f75844SAndroid Build Coastguard Worker`.cc` files in `api/` should preferably be kept reasonably small. If a 23*d9f75844SAndroid Build Coastguard Workersubstantial implementation is needed, consider putting it with our non-public 24*d9f75844SAndroid Build Coastguard Workercode, and just call it from the `api/` `.cc` file. 25