You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
1.2 KiB

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