Giter Site home page Giter Site logo

go-notes's Introduction

Good practices

Formatting

  • Formatting should be performed by gofmt.

Comments

  • Packages should have a top block comment for documentation - multi file packages should only have one comment.

  • Comments are plain text, no annotations for formatting is needed.

  • Comments preceding top-level declarations are used for documentation. Every exported name should have a doc comment.

    // Foo is an example of how doc comments should be.
    func Foo() {
    	return "foo"
    }
  • Related constants or variables may have only one comment to introduce them.

    // Dimentions of something.
    var(
    	length uint32
    	width uint32
    )

Names

Names have a semantic effect in Go. So naming is very important.

  • Go uses cammelCase and PascalCase to multiword names.
  • Names preceded with upper case are exported.

Packages

  • Package names should refer to it's content. They should be short, concise and evocative. Package names MUST:
    • Have one word.
    • Be lower case.
    • NOT have mixedCase or under_scores.

Getters and setters

  • Getters and setters may be used when necessary.
  • Getters should not take the prefix get . If there's a field name it's getter must be called Name .
  • Setters should take the prefix set. If there's a field name it's setter must be called SetName .

Interfaces

  • One-method interfaces should be named with the method's name followed by the suffix er . E.g. Reader , Writer .
  • Well-known method's names such as Read , Write , Flush, Close, should only be used if they have the same signature and meaning. E.g. a string converter should be called String not ToString.

Arrays and Slices

  • Array pointers like array *[10]float64 are not idiomatic and should be avoided. Slices should be used instead.

Style guides

Links

Reading

Links

Videos

Talks

go-notes's People

Contributors

thefuga avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.