- Hands-On Dependency Injection in Go
- Corey Scott
- 225字
- 2021-06-10 19:17:50
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.
- Mastering OpenLayers 3
- 軟件安全技術
- Python量化投資指南:基礎、數據與實戰
- Learning Firefox OS Application Development
- Hands-On Natural Language Processing with Python
- HTML5從入門到精通 (第2版)
- Mastering Business Intelligence with MicroStrategy
- Building Machine Learning Systems with Python(Second Edition)
- Service Mesh實戰:基于Linkerd和Kubernetes的微服務實踐
- OpenCV with Python By Example
- PHP編程基礎與實踐教程
- Citrix XenServer企業運維實戰
- ExtJS Web應用程序開發指南第2版
- Getting Started with Polymer
- Visual Basic語言程序設計基礎(第3版)