Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

71%
+3 −0
Q&A What are the benefits of including complete working code samples in documentation

There are different types of examples and they serve different purposes. One type is the quick-start example that this answer describes: a complete, but small, runnable example packaged in a form ...

posted 7y ago by Monica Cellio‭  ·  edited 3y ago by Monica Cellio‭

Answer
#4: Post edited by user avatar Monica Cellio‭ · 2021-06-20T20:13:58Z (over 3 years ago)
updated link
  • There are different types of examples and they serve different purposes.
  • One type is the **quick-start example** that [this answer](https://writing.stackexchange.com/a/33589/1993) describes: a complete, but small, runnable example packaged in a form that the users can easily use. "Hello world" is sometimes _too_ simple (simplistic), but this example should use defaults where possible and not bite off too much -- the user should be able to run it and understand what he's looking at without too much research. This example generally shouldn't be code in \<pre\> blocks that people have to cut and paste; attach or post the code, project files, data files, or whatever's needed alongside the doc instead.
  • Another type is the **focused excerpt** , such as you find in API reference documentation. On the reference page about a class and its member functions, you include example invocations of those member functions in isolation. On the reference page about an interface that the user will implement, you include example implementations of key functions. These examples are not complete and runnable; you use them to demonstrate specific, focused points. This approach isn't limited to API reference pages; on my current project we excerpt published examples in the programming guides, too.
  • Another type is the **full, realistic example**. (Or sometimes a **reference implementation**.) . As with the quick-start example, you post this code separately rather than embedding it into the documentation text (which would definitely be bloat). However, in the documentation you can provide an overview of this example -- structure, descriptions of key components, flow diagrams, class hierarchies, or whatever types of explanation make sense in your specific domain.
  • Complete examples, whether quick-start or fuller, should contain good internal comments that focus on _why_ and _how_, not just _what_. You're writing a sort of tutorial in the comments. Your comment-to-code ratio will probably be higher than in internal code, but it needn't be _that_ much higher. Your goal is concise yet informative.
  • There are different types of examples and they serve different purposes.
  • One type is the **quick-start example** that [this answer](https://writing.codidact.com/posts/26400#answer-26402) describes: a complete, but small, runnable example packaged in a form that the users can easily use. "Hello world" is sometimes _too_ simple (simplistic), but this example should use defaults where possible and not bite off too much -- the user should be able to run it and understand what he's looking at without too much research. This example generally shouldn't be code in \<pre\> blocks that people have to cut and paste; attach or post the code, project files, data files, or whatever's needed alongside the doc instead.
  • Another type is the **focused excerpt** , such as you find in API reference documentation. On the reference page about a class and its member functions, you include example invocations of those member functions in isolation. On the reference page about an interface that the user will implement, you include example implementations of key functions. These examples are not complete and runnable; you use them to demonstrate specific, focused points. This approach isn't limited to API reference pages; on my current project we excerpt published examples in the programming guides, too.
  • Another type is the **full, realistic example**. (Or sometimes a **reference implementation**.) . As with the quick-start example, you post this code separately rather than embedding it into the documentation text (which would definitely be bloat). However, in the documentation you can provide an overview of this example -- structure, descriptions of key components, flow diagrams, class hierarchies, or whatever types of explanation make sense in your specific domain.
  • Complete examples, whether quick-start or fuller, should contain good internal comments that focus on _why_ and _how_, not just _what_. You're writing a sort of tutorial in the comments. Your comment-to-code ratio will probably be higher than in internal code, but it needn't be _that_ much higher. Your goal is concise yet informative.
#3: Attribution notice added by user avatar System‭ · 2019-12-08T08:04:45Z (about 5 years ago)
Source: https://writers.stackexchange.com/a/33660
License name: CC BY-SA 3.0
License URL: https://creativecommons.org/licenses/by-sa/3.0/
#2: Initial revision by (deleted user) · 2019-12-08T08:04:45Z (about 5 years ago)
There are different types of examples and they serve different purposes.

One type is the **quick-start example** that [this answer](https://writing.stackexchange.com/a/33589/1993) describes: a complete, but small, runnable example packaged in a form that the users can easily use. "Hello world" is sometimes _too_ simple (simplistic), but this example should use defaults where possible and not bite off too much -- the user should be able to run it and understand what he's looking at without too much research. This example generally shouldn't be code in \<pre\> blocks that people have to cut and paste; attach or post the code, project files, data files, or whatever's needed alongside the doc instead.

Another type is the **focused excerpt** , such as you find in API reference documentation. On the reference page about a class and its member functions, you include example invocations of those member functions in isolation. On the reference page about an interface that the user will implement, you include example implementations of key functions. These examples are not complete and runnable; you use them to demonstrate specific, focused points. This approach isn't limited to API reference pages; on my current project we excerpt published examples in the programming guides, too.

Another type is the **full, realistic example**. (Or sometimes a **reference implementation**.) . As with the quick-start example, you post this code separately rather than embedding it into the documentation text (which would definitely be bloat). However, in the documentation you can provide an overview of this example -- structure, descriptions of key components, flow diagrams, class hierarchies, or whatever types of explanation make sense in your specific domain.

Complete examples, whether quick-start or fuller, should contain good internal comments that focus on _why_ and _how_, not just _what_. You're writing a sort of tutorial in the comments. Your comment-to-code ratio will probably be higher than in internal code, but it needn't be _that_ much higher. Your goal is concise yet informative.

#1: Imported from external source by user avatar System‭ · 2018-02-21T03:59:17Z (almost 7 years ago)
Original score: 2