---
title: "Discussion on \"Common anti-patterns in Go\" | Hashnode"
description: "Discussion on \"Common anti-patterns in Go\". It has been widely acknowledged that coding is an art, and like every artisan who crafts wonderful art and is proud of them, we as developers are also really proud of the code we write. In order to achieve the best results, artists constantly keep se..."
url: "https://hashnode.com/posts/common-anti-patterns-in-go/605ad82747b0d2243d4ab7ba"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Common anti-patterns in Go](https://deepsourcehq.hashnode.dev/common-anti-patterns-in-go?utm_source=hashnode&utm_medium=feed)

It has been widely acknowledged that coding is an art, and like every artisan who crafts wonderful art and is proud of them, we as developers are also really proud of the code we write. In order to achieve the best results, artists constantly keep se...

Mar 24, 2021 · 8 min read · deepsourcehq.hashnode.dev  
Updated Apr 2, 2021  
Read the article

-   [#go](https://hashnode.com/tag/go)
-   [#programming-tips](https://hashnode.com/tag/programming-tips)
-   [#coding](https://hashnode.com/tag/coding)

## Written by

[Saif Sadiq](https://hashnode.com/@saif309)

@saif309

  
[View profile](https://hashnode.com/@saif309)

Product Marketer

## Responses 3

Markdown supported · ⌘↵ to post

[Blake](https://hashnode.com/@dsbw)

[Apr 10, 2021](https://hashnode.com/posts/common-anti-patterns-in-go/605ad82747b0d2243d4ab7ba/comment/6071e7b78b2b857c0bdb61b8)

This is a good article but these aren't really anti-patterns, right? Like, if we were talking C, and I said:

Bad Practice: i = i + 1;

Good Practice: i++;

The first example isn't so much an anti-pattern as a novice mistake, not idiomatic or stylistic. One can, and many have, written perfectly fine software with misunderstandings or incomplete understanding of how a language works.

To be an anti-pattern, it has to be "ineffective and/or counterproductive in practice". And I think generally, if they're not straight-up wrong, they have to be a smell—an indication of a poor design choice. #1 works counts, I think.

#9 is akin to a "poltergeist" (an anti-pattern where an object does nothing but act through another object) but it's interesting to note that, in Go, this is far less serious because it's far less hidden. A lot of this stuff is something an experience Go programmer would just say, "Oh, yeah, you don't need that," and take it out on a casual pass-through.

Anti-patterns usually require more serious refactoring.

[Jorge Florian](https://hashnode.com/@jorgeflorian)

[Apr 14, 2021](https://hashnode.com/posts/common-anti-patterns-in-go/605ad82747b0d2243d4ab7ba/comment/6071e7b78b2b857c0bdb61b8#reply-6076b40ba3407a32d704119c)

Agree. I would call this some kind of coding best practices in the language.

[Sagar Jha](https://hashnode.com/@SagarJ)

[Mar 28, 2021](https://hashnode.com/posts/common-anti-patterns-in-go/605ad82747b0d2243d4ab7ba/comment/6060d3945aa4944ee40fa543)

Saif, the blog was really a pleasure to read and very informative. Would want to share feedback on two points.

For point 5: The function `printAndReturnFoofoo` where we have a named return type, we would get error if we try to initialize variable with same name inside the function, it is already initialized for the return, so we can update `foofoo := "foofoo"` to `foofoo = "foofoo"`

For point 9: The example is missing the simplified version.

[Saif Sadiq](https://hashnode.com/@saif309)

[Mar 31, 2021](https://hashnode.com/posts/common-anti-patterns-in-go/605ad82747b0d2243d4ab7ba/comment/6060d3945aa4944ee40fa543#reply-6064169d669be10bf6055677)

Hey [Sagar Jha](https://hashnode.com/@SagarJ),

Its great to hear that you found the post helpful. Thanks for the suggestion regarding the point 5. Have made the changes by removing the short variable declaration.

Regarding point 9, I think it does have a simplified solution. Here is an example to help you understand its simplified solution in a better way :

```
// add sums up x and y
func add(x int, y int) int {
    return x + y
}
func main() {
    complexFn := func(x int, y int) int { return add(x, y) }
    fmt.Println("sum:", complexFn(1,2))
    simpleFn := add
    fmt.Println("sum:", simpleFn(1,2))
}
```

Do let me know if you have any queries/thoughts. Thanks.

[Paul Hewlett](https://hashnode.com/@eccles)

[Mar 28, 2021](https://hashnode.com/posts/common-anti-patterns-in-go/605ad82747b0d2243d4ab7ba/comment/60606f8e38b0e14f092a3731)

There is something wrong with the code formatting - please fix...

[Saif Sadiq](https://hashnode.com/@saif309)

[Mar 30, 2021](https://hashnode.com/posts/common-anti-patterns-in-go/605ad82747b0d2243d4ab7ba/comment/60606f8e38b0e14f092a3731#reply-6063282c9be8d2084c02694f)

Fixed, thanks for noticing.
