Skip to content

Commit

Permalink
some more on setting up for refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
quii committed Apr 8, 2018
1 parent 60f7ecc commit f1fbfbb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions install-go.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ go get -u github.com/alecthomas/gometalinter
gometalinter --install
```

## Refactoring and your tooling

A big emphasis of this book is around the importance of refactoring. So many people practicing TDD forget or neglect this step.

Your tools can help you do bigger refactoring with confidence.

You should be familiar enough with your editor to perform the following with a simple key combination:

- **Extract/Inline variable**. Being able to take magic values and give them a name lets you simplify your code quickly
- **Extract method/function**. It is vital to be able to take a section of code and extract functions/methods
- **Rename**. You should be able to confidently rename symbols across files.
- **go fmt**. Go has an opinioned formatter called `go fmt`. Your editor should be running this on every file save.
- **Run tests**. It goes without saying that you should be able to do any of the above and then quickly re-run your tests to ensure your refactoring hasn't broken anything

In addition, to help you work with your code you should be able to:

- **View function signature** - You should never be unsure how to call a function in Go. Your IDE should describe a function in terms of its documentation, its parameters and what it returns.
- **View function definition** - If it's still not clear what a function does, you should be able to jump to the source code and try and figure it out yourself.
- **Find usages of a symbol** Being able to see the contest of a function being called can help your decision process when refactoring.


Mastering your tools will help you concentrate on the code and reduce context switching.

## Wrapping up

At this point you should have Go installed, an editor available and some basic tooling in place. Go has a very large ecosystem of third party products. We have identified a few useful components here, for a more complete list see https://awesome-go.com.

0 comments on commit f1fbfbb

Please sign in to comment.