On Thu, Jun 23, 2016 at 6:54 PM, Val  wrote:

Even in OO style (e.g. java), you would not be able to write
>  Set s = null;
>  s.init( list(1,2,3) );
>
> This is (more or less) the same problem with value receiver... the
> "constructor-like" idiom in go is a function NewSet, not a method :

 https://play.golang.org/p/_n56yMhlRt


* Now* I understand the reason behind such idiom in go. Yep, everything
makes sense now.

Thanks a lot for the clear explanation.
That really helps.

Hmm... wait,

map is a reference type


Does that means that, this function

    func (s set) Has(a string) bool { _, ok := s[a]; return ok }

is exactly the same as the following?

    func (s *set) Has(a string) bool { _, ok := (*s)[a]; return ok }

I.e., even the set is super super big, there is no pass-by-value penalty in
the first version?

Thx

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to