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

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.

主站蜘蛛池模板: 榆中县| 肇东市| 巴彦淖尔市| 绍兴县| 玉溪市| 长武县| 栾城县| 太谷县| 斗六市| 毕节市| 丰顺县| 淄博市| 安达市| 波密县| 遂平县| 泗洪县| 镇宁| 浏阳市| 耿马| 南充市| 习水县| 阳新县| 贺兰县| 固镇县| 浪卡子县| 青阳县| 聂拉木县| 巴林左旗| 年辖:市辖区| 卢湾区| 东方市| 东乡| 南投市| 深州市| 神池县| 乌苏市| 城市| 铜鼓县| 宾阳县| 东方市| 盐亭县|