- 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.
- Instant Node Package Manager
- Practical Data Analysis Cookbook
- Mobile Application Development:JavaScript Frameworks
- Reporting with Visual Studio and Crystal Reports
- Programming ArcGIS 10.1 with Python Cookbook
- 基于差分進化的優化方法及應用
- Spring實戰(第5版)
- Python:Master the Art of Design Patterns
- Swift 4從零到精通iOS開發
- Python爬蟲、數據分析與可視化:工具詳解與案例實戰
- Flask Web開發:基于Python的Web應用開發實戰(第2版)
- 百萬在線:大型游戲服務端開發
- JavaScript前端開發基礎教程
- Scratch編程從入門到精通
- Unity 5 Game Optimization