Похожие чаты

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 ответов

10 просмотров

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!

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

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

Всем привет, написал код ниже, но он выдает сегфолт, в чем причина? #include <stdio.h> #include <stdlib.h> #include <string.h> struct product { char *name; float price; };...
buzz базз
32
Хотел бы спросить у знающих, правильную ли я выбрал книгу для начала изучения ассемблера Юрова В.И ? Или есть более лучшие книги для начала обучения?
Botsman
25
Добрый день, не подскажите, если в OC-V3 поменять страндартную директорию /storage/ на /storage2/ - не будет сильно много проблем ?
Max Dubovsky
32
Книга Юрова В.И пойдёт для обучения?
Botsman
24
Conversation at a festival with a non-crpto person (not a normie by any stretch, though): * person: tell me about crypto, me: ok, the original idea is p2p sound money for the...
molecular#123 🐓
25
$params = [ 'formid' => 'feedbackForm', 'formTpl' => '@CODE: <form class="form-validate" data-id="ajax_form"> <fieldset class="margin-bottom-md"> ...
Pathologic
1
I bought some PHA tokens on Kucoin, which is the best wallet to store and easy to use?
AMR
19
Can you believe it? A whole new gaming ecosystem powered by FunToken! 😲
Josh
13
'frakturBold' => ['𝖆', '𝖇', '𝖈', '𝖉', '𝖊', '𝖋', '𝖌', '𝖍', '𝖎', '𝖏', '𝖐', '𝖑', '𝖒', '𝖓', '𝖔', '𝖕', '𝖖', '𝖗', '𝖘', '𝖙', '𝖚', '𝖛', '𝖜', '𝖝', '𝖞', '𝖟', '𝕬', '𝕭', '𝕮', '𝕯'...
Roma
4
Подскажите пожалуйста, а я могу вот такую штуку использовать? rpc, только реализованное в реббите https://www.rabbitmq.com/tutorials/tutorial-six-php ( или https://habr.com/ru...
Artyom
11
Карта сайта