Monday, September 10, 2012

Google Go tips

BUT CONCLUSION:

You're not writing distributed server software, you're writing for and on top of already set-up distributed servers, so you just use Python to code your application software.

So, forget about Go.

The naming and organization tips here are still relevant, for Python, or anytime, though.





http://blog.golang.org/2012/08/organizing-go-code.html


Organizing Go code

Go code is organized differently to that of other languages. This post discusses how to name and package the elements of your Go program to best serve its users.

Choose good names

The names you choose affect how you think about your code, so take care when naming your package and its exported identifiers.

A package's name provides context for its contents. For instance, the bytes package from the standard library exports the Buffer type. On its own, the name Buffer isn't very descriptive, but when combined with its package name its meaning becomes clear: bytes.Buffer. If the package had a less descriptive name, like util, the buffer would likely acquire the longer and clumsier name util.BytesBuffer.

Don't be shy about renaming things as you work. As you spend time with your program you will better understand how its pieces fit together



What to put into a package

Look to the Go standard libraries as a guide. Some of its packages are large and some are small. For instance, the http package comprises 17 go source files (excluding tests) and exports 109 identifiers, and the hash package consists of one file that exports just three declarations. There is no hard and fast rule; both approaches are appropriate given their context.










No comments:

Post a Comment