同步阅读进度,多语言翻译,过滤屏幕蓝光,评论分享,更多完整功能,更好读书体验,试试 阅读 ‧ 电子书库
Variables and Constants
Headers and comments are just one way to document your code. Another is by the use of descriptive variable names. Good variable names should give an indication of what the variable represents. Names like "x", "resn" or "procd" will only have meaning at the time that you write the script. Six months down the track and they will be a mystery.
Good names should be short but descriptive. The three examples above might have been more meaningfully written as "file_limit", "resolution", and "was_processed". Don't make the names too long; the name "horizontal_resolution_of_the_picture" just clutters a script and takes away any advantage in making the name so descriptive.
Constants should be in uppercase and should normally be declared as read-only:
declare -r CAPITAL_OF_ENGLAND="London"
You should always avoid "magic numbers" sprinkled throughout the code by using constants. For example:
if [[ $process_result == 68 ]]
...
should be replaced with:
declare -ir STAGE_3_FAILURE=68
...
if [[ $process_result == $STAGE_3_FAILURE ]]
...
Not only does this make the code more readable but it makes changing the value easier, especially if it is used numerous times in the script.
请支持我们,让我们可以支付服务器费用。
使用微信支付打赏
