> For the complete documentation index, see [llms.txt](https://docs.docbits.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.docbits.com/chinese/guan-li-yu-she-zhi/settings/global-settings/document-types/script/best-practices-5.md).

# 最佳实践

## 以下是 DocBits 脚本开发的一些最佳实践，例如保持脚本模块化、妥善处理错误，并记录每个脚本的用途和功能。

### 模块化开发：

* 保持脚本模块化且结构清晰。
* 将复杂任务拆分为更小、更易管理的模块。
* 这样不仅能让脚本更易于维护和更新，还能复用代码并提高可读性。

### 错误处理：

* 在脚本中实现健壮的错误处理。
* 确保代码能够检测错误情况并妥善响应，例如捕获并记录错误、提供有帮助的错误消息，或采取措施进行恢复。

### 文档说明：

* 详细记录每个脚本的用途、功能和用法。
* 说明脚本执行哪些任务、预期输入是什么、生成哪些输出，以及它如何与文档处理工作流集成。
* 清晰的文档说明有助于其他开发人员理解和维护脚本。

### 注释：

* 充分注释代码，解释其功能和逻辑。
* 使用有意义的注释说明重要步骤或复杂的代码部分。
* 这不仅能让其他人更容易理解代码，也有助于你在今后进行更改或更新时理解代码。

### 版本控制：

* 为脚本实施有效的版本控制系统。
* 这样可以跟踪更改、管理不同版本，并在需要时还原到先前版本。
* 在多名开发人员共同处理同一脚本，或需要测试不同迭代版本时，这尤其有用。

### 安全性：

* 确保脚本安全，不存在潜在的安全漏洞。
* 例如，避免直接执行用户输入或以纯文本形式存储敏感信息等不安全做法。
* 应实施安全最佳实践，并定期审查代码中的安全漏洞。

遵循这些 DocBits 脚本开发最佳实践，你可以创建高效、可靠且文档齐全的脚本，从而提升文档处理工作流的功能和安全性。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.docbits.com/chinese/guan-li-yu-she-zhi/settings/global-settings/document-types/script/best-practices-5.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
