circle-exclamation
Deeplint is still in the MVP development phase and not yet available for use.

Code Examples Guidelines

This document provides guidelines for creating and maintaining code examples in the DeepLint documentation. Following these guidelines ensures that code examples are consistent, clean, and helpful for users.

General Principles

Clean Code

Code examples should follow the clean code principles and be self-explanatory whenever possible. This means:

  • Use descriptive variable and function names

  • Keep functions small and focused

  • Follow consistent formatting

  • Avoid unnecessary complexity

Minimal Examples

Examples should be minimal and focused on illustrating a specific concept or feature. Remove any code that isn't directly relevant to what you're demonstrating.

Real-World Relevance

While examples should be minimal, they should also be realistic and demonstrate practical use cases that users might encounter.

Comments in Code Examples

When to Use Comments

Comments in code examples should be used sparingly and only when they add value:

  • Use comments to explain "why", not "what" or "how"

  • Use comments to highlight important concepts that might not be immediately obvious

  • Use comments to indicate where code has been omitted for brevity

When to Avoid Comments

Avoid comments that:

  • Simply restate what the code is doing

  • Could be made unnecessary by using better variable or function names

  • Explain basic programming concepts that the target audience should already understand

  • Are outdated or incorrect

Comment Style

When comments are necessary:

  • Keep them brief and to the point

  • Use consistent style (e.g., // Comment for single-line comments)

  • For multi-line comments, use // Comment line 1 and // Comment line 2 rather than /* ... */

  • Place comments on their own line before the code they describe, not at the end of lines

Examples

Example 1: Unnecessary Comments

Example 2: Better Without Comments

Example 3: Appropriate Comments

Example 4: JSDoc Comments

Best Practices for Different Types of Code Examples

Command Line Examples

For command line examples:

  • Use comments to explain the purpose of commands

  • Include expected output when relevant

  • Use # for comments in bash code blocks

Configuration Examples

For configuration examples:

  • Use comments to explain non-obvious options

  • Include only relevant configuration sections

  • Show both JavaScript and YAML examples when applicable

API Usage Examples

For API usage examples:

  • Focus on the specific API being documented

  • Include error handling when relevant

  • Show complete, working examples

Implementation Guidelines

When implementing these guidelines:

  1. Review existing documentation for unnecessary comments in code examples

  2. Prioritize user-facing documentation (Getting Started guides, README, etc.)

  3. Be consistent across all documentation

  4. Test code examples to ensure they work as expected

  5. Update examples when the API or behavior changes

Checklist for Code Examples

Use this checklist when creating or reviewing code examples:

Conclusion

By following these guidelines, we can ensure that code examples in the DeepLint documentation are clean, consistent, and helpful for users. Remember that the goal of code examples is to illustrate concepts and features in a way that is easy to understand and apply.

Last updated