官术网_书友最值得收藏!

Follow industry, team, and language conventions

Concepts, variables, and function names all just make sense when they follow conventions. Ask yourself, if you are working on a system about cars, what would you expect a variable called flower to be?

Coding style is arguably something that Go got right. For many years, I was part of the bracket placement and the tab versus spaces wars, but when switching to Go, all of that changed. There is a fixed, documented, and easily reproducible style—run gofmt, problem solved. There are still some places where you can hurt yourself. Coming from a language with unchecked exceptions, you might be tempted to use Go's panic() phrase; while possible, it is one of several conventions explicitly discouraged in the official Code Review Comments wiki (https://github.com/golang/go/wiki/CodeReviewComments).

Team conventions are a little bit harder to define, and perhaps sometimes to follow. Should a variable of the channel type be called result, resultCh, or resultChan? I have seen, and probably written, all three.

How about error logging? Some teams like to log errors at the point at which they are triggered, and others prefer to do so at the top of the call stack. I have a preference, as I am sure you do, but I have yet to see an overwhelmingly compelling argument for either.

主站蜘蛛池模板: 泸州市| 逊克县| 黄浦区| 登封市| 安吉县| 涞水县| 正安县| 洪泽县| 遵义市| 青冈县| 黔西县| 东乡| 务川| 桐庐县| 安岳县| 鄯善县| 赤峰市| 漳浦县| 宁阳县| 马山县| 麻城市| 四会市| 墨竹工卡县| 金坛市| 洪泽县| 永靖县| 布拖县| 高邑县| 永和县| 化德县| 江口县| 郎溪县| 盘锦市| 班玛县| 甘孜县| 永和县| 泸定县| 白城市| 边坝县| 呼玛县| 汕尾市|