Archive

这里是一些被封存的内容, 他们大部分年代古早, 内容质量低下; 也有考虑转为草稿内容后重新编辑再发布, 不过这些内容可能已经不够有趣或者选材不够好, 等不到回炉重造的机会了, 就另起一个类别, 专门封存这些低质量的内容; 后续再考虑删除/合并这些内容.


LFS包管理与Shell脚本

 Linux  Shell  包管理  LFS 󰈭 7312字
参考文档 More Control and Package Management using Package Users (v1.4) 工具包: more_control_helpers Shell 编程 特殊变量 $开头的一些特殊变量: Text  󰄬 1Special Parameters 2 The shell treats several parameters specially. These parameters may only 3 be referenced; assignment to them is not allowed. 4 * Expands to the positional parameters, starting from one. When the 5 expansion is not within double quotes, each positional parameter expands to 6 a separate word. In contexts where it is performed, those words are 7 subject to further word splitting and pathname expansion. When the 8 expansion occurs within double quotes, it expands to a single word with the 9 value of each parameter separated by the first character of the IFS 10 special variable. That is, "$*" is equivalent to "$1c$2c...", where c 11 is the first character of the value of the IFS variable. If IFS is unset, 12 the parameters are separated by spaces. If IFS is null, the parameters are 13 joined without in‐ tervening separators. 14 @ Expands to the positional parameters, starting from one. In 15 contexts where word splitting is performed, this expands each positional 16 parameter to a separate word; if not within double quotes, these words are 17 subject to word splitting. In contexts where word splitting is not 18 performed, this expands to a single word with each po‐ sitional parameter 19 separated by a space. When the expansion occurs within double quotes, 20 each parameter ex‐ pands to a separate word. That is, "$@" is 21 equivalent to "$1" "$2" ... If the double-quoted expansion occurs within a 22 word, the expansion of the first parameter is joined with the beginning 23 part of the original word, and the expansion of the last parameter is 24 joined with the last part of the original word. When there are no posi‐ 25 tional parameters, "$@" and $@ expand to nothing (i.e., they are removed). 26 # Expands to the number of positional parameters in decimal. 27 ? Expands to the exit status of the most recently executed foreground 28 pipeline. 29 - Expands to the current option flags as specified upon invocation, by 30 the set builtin command, or those set by the shell itself (such as the -i 31 option). 32 $ Expands to the process ID of the shell. In a () subshell, it 33 expands to the process ID of the current shell, not the subshell. 34 ! Expands to the process ID of the job most recently placed into the 35 background, whether executed as an asynchronous command or using the bg 36 builtin (see JOB CONTROL below). 37 0 Expands to the name of the shell or shell script. This is set 38 at shell initialization. If bash is invoked with a file of commands, $0 is 39 set to the name of that file. If bash is started with the -c option, then 40 $0 is set to the first argument after the string to be executed, if 41 one is present. Otherwise, it is set to the filename used to invoke bash, 42 as given by argument zero. type命令 默认的man好像显示的不是bash command的type, 因而去别处找了一份mannual: ...

Go 高质量编程

 Go 󰈭 1572字
编码规范 代码格式 一定使用gofmt进行格式化。 注释 解释代码的作用 这种注释适合说明公共符号,比如注释解释向外提供的函数等,只有在函数功能简单而明显时才应该省略这些注释。 解释代码的实现 对代码中复杂、隐晦的逻辑进行说明。不要使用自然语言直接翻译代码,这不好。 解释代码实现的原因 注释可以解释代码的外部因素,这些因素脱离了上下文后通常难以理解。 解释代码可能出错的情况 注释应该提醒使用者一些潜在的限制条件或者无法处理的情况。 公共符号的注释 Google Style指南有两条规则:任何既不明显也不简短的公共功能必须予以注释;无论长度或者复杂度如何,库中的任何函数都必须予以注释。一个例外是,不要注释实现接口的方法! 命名规范 变量 简洁胜于冗长 缩略词使用全大写(如HTTP,XML等),但当其位于变量开头且不需要导出时,使用全小写(如使用ServeHTTP而不是ServeHttp, 使用XMLHTTPRequest或者xmlHTTPRequest) 全局变量在名字中需要携带更多的上下文信息,使得不同地方都可以轻易辨认出其含义。 函数 函数名不包含包名的上下文信息,因为包和函数总是成对出现的。 尽量简短 当名为foo的包中某个函数的返回类型是Foo时,可以省略类型信息而不产生歧义,当返回的是其余类型时,则可以在函数名中加入类型信息。 包 只有小写字母组成。 简短并包含一定的上下文信息 不和标准库同名。 尽量满足以下规则: 不使用常用变量名作为包名 使用单数而不是复数 谨慎地使用缩写,利用使用fmt在不破坏上下文的情况下比format更加简短。 控制流程 遵循线性原理,尽量避免嵌套,保持正常流程清晰。 尽量保持正常代码路径为最小缩进,优先处理特殊、错误情况,尽早开始重新循环来减少嵌套。 错误和异常处理 简单错误 简单错误是指金出现一次的错误,且在其他地方不需要捕获该错误,则优先使用error.New来创建匿名变量直接表示简单错误;如果有格式化的要求,使用fmt.Errorf ...