macos:Reliability
出自UXGuide.net
请帮助我们修订和更新本文的中文部分
本文的中文部分虽然取自官方最新中文版本,但与英文原版相比已落后了一年多,可能无法反映英文版本中最近的修改,且文中笔误、前后译法矛盾、未翻译完全的片断较多,请您帮助一起修订完善。详情参见中文版修订完善计划。
可靠
Reliability
A reliable program is one that earns the user’s trust. Such a program presents information to the user in an expected and desired way. A reliable program maintains the integrity of the user’s data and does everything possible to prevent data loss or corruption. It also has a certain amount of maturity to it and can handle complex situations without crashing.
可靠的程序才会赢得用户的信任。这样的程序总是将信息以用户期望的方式呈献给用户,总是能够保证用户数据的完整性并且尽一切可能的防止用户数据的丢失和损坏。可靠的程序能够处理很复杂的情况而不会崩溃。
Reliability is important in all areas of software design, but especially in areas where a program may be running for an extended period of time. For example, scientific programs often perform calculations on large data sets and can take a long time to complete. If such a program were to crash during a long calculation, the scientist could lose days or weeks worth of work.
可靠性在软件设计中十分重要,尤其是一个程序需要长期的运行时。例如,进行科学计算的程序经常需要很长时间来计算大量的数据。如果这样的程序在长期计算的过程中崩溃了,就可能浪费了科学家们好几个星期的工作。
Here are some guidelines to keep in mind as you design your software for reliability:
下面是在软件设计中关于可靠性的一些准则:
- Make sure your user interface behaves in a predictable way. The same set of actions should generate the same results each time. See “Consistency” for additional information.
- 确保用户接口的行为可预期。同样的操作应该导致同样的结果。更多信息请参考“一致性”一节。
- Provide predictable output from your documents. For printing, make sure that the content the user sees on the screen is what gets printed. (Note that the Mac OS X printing dialogs provide a print preview option for you.)
- 提供可预期的文档输出结果。例如打印,确保用户在屏幕所见的内容和打印出来的内容一致。(注意 Mac OS X 的打印对话框为您提供了打印预览的选项。)
- Reduce or eliminate data loss when importing or exporting documents. If your program imports or exports files associated with other applications, make sure you fully support the file format. If your application cannot import all data from a given file format, warn the user that data loss may occur and offer the option to work on a copy of the original file.
- 减少或者消除导入或者导出文档时的数据丢失。如果您的程序需要导入或者导出和别的程序相关的文件,请确保您已经完全支持了该文件格式。如果您的程序不能导入给定文件格式的所有数据,您应该警告用户数据可能丢失并且提供选项以维护一份原文件副本。
- Test your software under a wide variety of conditions and verify that it responds appropriately. Simulate the network going down or a mounted volume disappearing and ensure that your software adapts appropriately.
- 在多种条件下对您的程序进行广泛测试以确保工作正常。模拟网络断开和已经打开的卷消失的情况来确保您的程序可以正确处理这些情况。
- Make sure your packaging clearly indicates the system requirements for your software. Don’t assume your software runs on lower-end hardware until you test it on that hardware. Similarly, indicate which versions of Mac OS X you support.
- 确保您的程序安装包清楚地标明了对系统的要求。除非您已经在低端硬件上测试过,否则不要假设您的程序可以在这些硬件上工作。类似的,标明您的程序支持的Mac OS X版本。
- Anticipate errors and handle them gracefully. If a function returns a result code, check it to see if there was a problem and respond appropriately. You can also use exception handlers to catch errors; however, use them sparingly. Exception handlers increase the memory footprint of your application, which can degrade performance.
- 预先处理错误。检查函数的返回值来确定是不是有错误发生。您也可以使用异常处理机制来捕捉错误。然而, 尽量少用。异常处理增加了内存占用量,会降低您的程序性能。
- Validate user input to ensure that it is what you expect. Formatter objects help ensure that users enter numbers and dates correctly. (For information on formatting data in a Carbon application, see Data Formatting Guide for Core Foundation. For information on formatting data in a Cocoa application, see Data Formatting Programming Guide for Cocoa.) Your own code should validate user-entered data to prevent it from causing problems later. See “The Functions of Specific Keys” for information on how a user uses specific keys to enter data.
- 验证用户的输入以确保它符合您的预期。Formatter对象能够帮助您确保用户正确的输入了数字和日期。(关于Carbon程序中格式化数据的更多信息,请参考 Core Foundation 中的格式数据编程指南。关于Cocoa程序中的格式化数据信息,请参考 Cocoa 中的格式数据编程指南。)您的代码也应该验证用户输入的数据以免程序出错。关于怎样要求用户使用指定按键输入数据的更多信息请参考“指定按键输入”。
- Use the Apple-provided performance and debugging tools to find memory leaks and other problem areas in your code. These tools can uncover hidden bugs that you did not know you had.
- 使用 Apple 提供的性能和调式工具来寻找代码中的内存泄露和其他问题。这些工具能帮您找到您自己还没有意识到的 bug。
- Choose modern APIs over legacy APIs. Modern APIs provide better handling of system configuration changes than legacy APIs.
- 使用新的 API 代替早期的 API。新的 API 比老的 API 能更好的处理系统配置的改动。
- Prefer system and standards-based APIs to your own custom APIs. See “Using Mac OS X Technologies” for additional information.
- 尽可能的使用系统提供的或者基于标准的 API 而不是您自己定制的 API。更多信息请参考“使用 Mac OS X 技术”。