---
title: "Comment by Maxim Pak on \"Top 5 Lessons I learned while working with Go for two years\" | Hashnode"
description: "As far as I know, in most cases singletons are considered an anti-pattern. It&#39;s probably better to explicitly pass *sql.DB object around"
url: "https://hashnode.com/posts/top-5-lessons-i-learned-while-working-with-go-for-two-years/60a8fb2e5379f65d10b5f642/comment/60b1587dfb51fd32a4dbf700"
---

[Discussion](https://hashnode.com/posts/top-5-lessons-i-learned-while-working-with-go-for-two-years/60a8fb2e5379f65d10b5f642)

Comment [Top 5 Lessons I learned while working with Go for two years](https://hashnode.com/posts/top-5-lessons-i-learned-while-working-with-go-for-two-years/60a8fb2e5379f65d10b5f642)

[Maxim Pak](https://hashnode.com/@xFox)

[May 28, 2021](https://hashnode.com/posts/top-5-lessons-i-learned-while-working-with-go-for-two-years/60a8fb2e5379f65d10b5f642/comment/60b1587dfb51fd32a4dbf700)

As far as I know, in most cases singletons are considered an anti-pattern. It's probably better to explicitly pass \*sql.DB object around

[Sayed Alesawy](https://hashnode.com/@sayedalesawy)

[May 29, 2021](https://hashnode.com/posts/top-5-lessons-i-learned-while-working-with-go-for-two-years/60a8fb2e5379f65d10b5f642/comment/60b1587dfb51fd32a4dbf700#reply-60b1ef809b1e2e1dccbce010)

I am not really sure why do you think so. I mean my rationale is that you will probably need to do some initialization of some sort, like maybe pass connection configurations or something like that. You will probably do it in an init method or something, then after that you can use the connection variable. Looks like if somebody forgot to init, they will run into problems and here comes the usefulness of having a wrapper method. And if you have a wrapper method and it's not singleton, that will be problematic as well.

I am interested to know why do you think it's an anti pattern or if you have a resource that supports that. Thanks for the thought tho!
