- 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
推薦閱讀
- Learning Microsoft Windows Server 2012 Dynamic Access Control
- 構建移動網站與APP:HTML 5移動開發入門與實戰(跨平臺移動開發叢書)
- C語言程序設計基礎與實驗指導
- 算法訓練營:入門篇(全彩版)
- 跟小海龜學Python
- Securing WebLogic Server 12c
- Effective Python Penetration Testing
- JavaScript 程序設計案例教程
- 網站構建技術
- HTML5從入門到精通 (第2版)
- 計算機應用基礎教程(Windows 7+Office 2010)
- Nagios Core Administration Cookbook(Second Edition)
- 實戰Java高并發程序設計(第2版)
- Redmine Cookbook
- C語言程序設計實驗指導與習題精解