Skip to content

Instantly share code, notes, and snippets.

@expose
Created March 11, 2025 05:50
Show Gist options
  • Save expose/4fe1cc356af32a140a9917368e07aefb to your computer and use it in GitHub Desktop.
Save expose/4fe1cc356af32a140a9917368e07aefb to your computer and use it in GitHub Desktop.
Windsurf global rules template

Global Rules

These guidelines ensure consistency, quality, and maintainability across all projects. They provide foundational principles that apply regardless of specific architecture patterns or methodologies.

Code Style and Readability

  1. Clarity is Paramount:

    • Write code that clearly communicates intent.
    • Favor understandable code over clever tricks or excessive brevity.
    • Use descriptive, consistent naming following language conventions.
  2. Consistent Formatting:

    • Maintain uniform indentation, spacing, and line width.
    • Leverage automated tools (linters, formatters) to enforce consistency.
  3. Purposeful Comments:

    • Write comments explaining the "why" behind complex logic or business rules.
    • Avoid redundant comments that merely restate the code.
    • Document architectural decisions and non-obvious constraints.
  4. Function Design:

    • Create small, focused functions with single responsibilities.
    • Keep functions concise with clear inputs and outputs.

Architecture and Design

  1. Modularity:

    • Encapsulate complexity behind clean interfaces.
    • Decouple components to minimize dependencies.
    • Follow DRY (Don't Repeat Yourself) principles judiciously.
  2. Testability:

    • Design for testability from the start.
    • Separate pure logic from side effects.
    • Make dependencies explicit and injectable.

Error Handling and Validation

  1. Robust Error Management:

    • Fail fast with clear error messages.
    • Handle edge cases deliberately, not as afterthoughts.
    • Validate inputs comprehensively.
  2. Security Mindfulness:

    • Sanitize user inputs and validate data from external sources.
    • Consider security implications in all data handling.

Performance and Resources

  1. Efficient Resource Usage:

    • Manage resources (memory, connections, files) properly throughout their lifecycle.
    • Choose appropriate data structures and algorithms for the problem.
  2. Balanced Optimization:

    • Prioritize correct, maintainable solutions first.
    • Optimize based on measured performance needs, not assumptions.
    • Document performance-critical sections.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment