- Go Systems Programming
- Mihalis Tsoukalos
- 235字
- 2021-07-02 18:08:04
Avoiding common Go mistakes
This section will briefly talk about some common Go mistakes so that you can avoid them in your programs:
- If you have an error in a Go function, either log it or return it; do not do both unless you have a really good reason to do so.
- Go interfaces define behaviors, not data and data structures.
- Use the io.Reader and io.Writer interfaces because they make your code more extensible.
- Make sure that you pass a pointer to a variable to a function only when needed. The rest of the time, just pass the value of the variable.
- Error variables are not strings; they are error values.
- If you are afraid of making mistakes, you will most likely end up doing nothing useful. So experiment as much as you can.
The following are general pieces of advice that can be applied in every programming language:
- Test your Go code and functions in small and autonomous Go programs to make sure that they behave the way you think they should
- If you do not really know a Go feature, test it before using it for the first time, especially if you are developing a systems utility
- Do not test systems software on production machines
- When you deploy your systems software on a production machine, do it when the production machine is not busy and make sure that you have a backup plan
推薦閱讀
- 手機安全和可信應用開發指南:TrustZone與OP-TEE技術詳解
- HTML5 移動Web開發從入門到精通(微課精編版)
- Django Design Patterns and Best Practices
- Mastering Apache Spark 2.x(Second Edition)
- Scala編程實戰(原書第2版)
- SQL Server 2008 R2數據庫技術及應用(第3版)
- Mastering Elixir
- 基于GPU加速的計算機視覺編程:使用OpenCV和CUDA實時處理復雜圖像數據
- Java RESTful Web Service實戰
- Building a Media Center with Raspberry Pi
- Beginning PHP
- Three.js Essentials
- Visual Basic程序設計
- SFML Essentials
- 流程讓管理更高效:流程管理全套方案制作、設計與優化