mirror of
https://github.com/Pungyeon/clean-go-article.git
synced 2024-11-10 01:14:04 +00:00
Move RabbitMQ link to where it's first referenced
This commit is contained in:
parent
eba4b5f6e8
commit
2bc154d3b6
|
@ -344,7 +344,7 @@ func GetItemIfActive(extension string) (Item, error) {
|
|||
|
||||
Creating a good function naming structure makes it easier to read and understand the intent of the code. As we saw above, making our functions shorter helps us understand the function's logic. The last part of cleaning our functions involves understanding the context of the function input. With this comes another easy-to-follow rule: <strong>Function signatures should only contain one or two input parameters</strong>. In certain exceptional cases, three can be acceptable, but this is where we should start considering a refactor. Much like the rule that our functions should only be 5–8 lines long, this can seem quite extreme at first. However, I feel that this rule is much easier to justify.
|
||||
|
||||
Take the following function from RabbitMQ's introduction tutorial to its Go library:
|
||||
Take the following function from [RabbitMQ's introduction tutorial to its Go library](https://www.rabbitmq.com/tutorials/tutorial-one-go.html):
|
||||
|
||||
```go
|
||||
q, err := ch.QueueDeclare(
|
||||
|
@ -418,8 +418,6 @@ Basically, we create a new structure named `RMQChannel` that contains the `amqp.
|
|||
|
||||
We'll use this idea of wrapping functions to introduce more clean and safe code later when discussing `interface{}`.
|
||||
|
||||
Related resource: [RabbitMQ Go tutorial](https://www.rabbitmq.com/tutorials/tutorial-one-go.html)
|
||||
|
||||
### Variable Scope
|
||||
Now, let's take a step back and revisit the idea of writing smaller functions. This has another nice side effect that we didn't cover in the previous chapter: Writing smaller function can typically eliminate reliance on mutable variables that leak into the global scope. Writing code with global variables is a practice of the past—it doesn't belong in clean code. But why is that?
|
||||
|
||||
|
|
Loading…
Reference in a new issue