Похожие чаты

Can someone pls explain this? Here is the source code for

sync.waitgroup:
https://golang.org/src/sync/waitgroup.go?s=2022:2057#L43

Why does the (T *WaitGroup) receiver not throw an error when I call it on a non-pointer type (T WaitGroup) ?

5 ответов

24 просмотра

As a rule of thumb, I personally use a pointer reciver in case I want to mutate something inside the struct. And non pointer in case I don't want to

Justin-K Автор вопроса
A​kshit
As a rule of thumb, I personally use a pointer rec...

Thanks, I have been doing this too. I got confused earlier with ‘pointer/non pointer’ consideration with interfaces vs their general reference use. I have replicated a few examples and now understand this nuance much better.

https://play.golang.org/p/4IQzUJyw0_o a pointer-reciver just takes the pointer of the variable you're calling it on+

Justin-K Автор вопроса
Roman Sharkov
https://play.golang.org/p/4IQzUJyw0_o a pointer-r...

Thank you, I understand that. I'm going to send a playground link in a bit of what actually got me confused.

Justin-K Автор вопроса
Roman Sharkov
https://play.golang.org/p/4IQzUJyw0_o a pointer-r...

https://play.golang.org/p/YdinlQBN_0E For a moment, I mixed up subtle differences between interface and concrete types, in the context of a method receiver. (Refer to line 31 and 28. ) I mistook that for a non-pointer type, I could not call its pointer receiver (as with type interface). I know better now but please do correct me if you notice gap in my understanding. Thanks!

Похожие вопросы

Обсуждают сегодня

30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Also, why can’t the community have a vote/ say when it comes to initiatives like buybacks. Isn’t the point of crypto decentralisation? Don’t we deserve input as long term supp...
👨🏽‍🦰
13
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
16
any reference of this implementation?
BitBuddha
29
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
13
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Карта сайта