-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Foundations of API Design chapter #2994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
(GitHub does not allow me to leave a comment on an empty file) |
| @@ -0,0 +1,3 @@ | |||
| --- | |||
| minutes: 2 | |||
| --- | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you intend to add something here?
At the very least, a title and {{%segment outline}} are needed.
| It's important to write doc comments that developers will appreciate reading, | ||
| that gives them the information they are looking for and doesn't just re-state | ||
| the obvious. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| It's important to write doc comments that developers will appreciate reading, | |
| that gives them the information they are looking for and doesn't just re-state | |
| the obvious. | |
| Good doc comments provide information that the code, names, and types | |
| cannot, without restating the obvious information. |
More concise wording; more actionable ("information they are looking for" - not very actionable); more common spelling ("restate");.
| Function names and type signatures already document some information, avoid | ||
| repeating them! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Function names and type signatures already document some information, avoid | |
| repeating them! | |
| Names and type signatures communicate a lot of information, don't repeat it in comments! |
| /// Parses an ipv4 from a str. Returns an option for failure modes. | ||
| fn parse_ip_addr_v4(input: &str) -> Option<IpAddrV4> { ... } | ||
|
|
||
| // TODO: couple more of these, for the instructor to go through with students. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My favorite:
struct BusinessAsset {
/// The customer id.
let customer_id: u64,
}
| ``` | ||
|
|
||
| <details> | ||
| - Motivation: Documentation that repeats name/signature information provides nothing new to the API user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - Motivation: Documentation that repeats name/signature information provides nothing new to the API user. | |
| - Motivation: Documentation that merely repeats name/signature information provides nothing new to the API user. |
| ``` | ||
|
|
||
| <details> | ||
| - Motivation: It can be easy to fall into a pattern of writing only for you, but most documentation is for people coming in with a different perspective. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - Motivation: It can be easy to fall into a pattern of writing only for you, but most documentation is for people coming in with a different perspective. | |
| - Background: The [curse of knowledge](https://en.wikipedia.org/wiki/Curse_of_knowledge) is a cognitive bias where experts assume that others have the same level of expertise and perspective. | |
| - Motivation: Your reader does not have the same level of expertise and the same perspective as you. Don't write for people like yourself, write for others. |
|
|
||
| ```rust | ||
| // TODO: What's a good illustration here? | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// expert writes for experts
/// Canonicalizes the MIR for the borrow checker.
///
/// This pass ensures that all borrows conform to the NLL-Polonius constraints
/// before we proceed to MIR-to-LLVM-IR translation.
pub fn canonicalize_mir(mir: &mut Mir) {
// ...
}
// expert writes for newcomers
/// Prepares the Mid-level IR (MIR) for borrow checking.
///
/// The borrow checker operates on a simplified, "canonical" form of the MIR.
/// This function performs that transformation. It is a prerequisite for the
/// final stages of code generation.
///
/// For more about Rust's intermediate representations, see the
/// [rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/mir/index.html).
pub fn canonicalize_mir(mir: &mut Mir) {
// ...
}| much information. | ||
| - Always ask: Is this documentation making it difficult for the API user? Are | ||
| they able to quickly grasp what they need or find out where they could need | ||
| it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also say something like "Experts also read API level documentation. Doc comments might not be the right place to educate your audience about the basics of your domain. In that case, signpost and namedrop - divert people to long-form documentation."
|
|
||
| # Predictable API | ||
|
|
||
| Keep your APIs predictable through naming conventions and implementing common |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Keep your APIs predictable through naming conventions and implementing common | |
| Keep your APIs predictable by following naming conventions and implementing common |
Parallel sentence structure.
| Keep your APIs predictable through naming conventions and implementing common | ||
| traits. | ||
|
|
||
| <!-- TODO --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some speaker notes would be nice. What is the framing for this section?
gribozavr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(misclick, I meant to simply "comment", but clicked "approve"; for clarity switching to "request changes")
Includes most of chapter 1 of foundations of API Design for Idiomatic Rust. Brought in from the gdoc. Tests have not been run locally yet, formatting has.