4 ms·
nil is just the empty value for slices maps pointers interfaces functions and channels. the only slightly confusing part is that interface objects are proxies
by dbt00 6y ago
nil is just the empty value for slices maps pointers interfaces functions and channels.
the only slightly confusing part is that interface objects are proxies that wrap a pointer and a type, so a nil pointer inside an interface is non-nil.
Writing idiomatic go this does come up but not nearly as when you do stuff like this.
- Kiro 6y ago> is just Considering you replied to a JavaScript comparison I, as a JS dev, would expect to understand at least one word of what you just wrote. If this is the easy explanation I think Go is out of my league.
- vineyardmike 6y agoThat’s the wrong attitude! Go is not out of anyone’s league. Certainly not someone who already can program. Not understanding a comment on HN is not particularly surprising and need not be a proxy for ability. I think this is unfairly self critical. (At least for anyone else reading this, maybe the original poster meant it in jest).
- why_Mr_Anderson 6y agoEvery time I see any Go code, it looks like the language was designed with primary goal being as different from everything else as possible. If there is X ways something is done (and you could then relate to that knowledge), you can be sure Go uses something different.
- hnlmorg 6y agoGenuine question: what languages have you tried and are comparing Go against? I ask because if anything, Go is as mediocre as they come with regards to it's design. There's very little about Go that stands out as being different. For many, that's it's attraction: it doesn't try to do much different and instead focuses on the basics. For others that's what's off putting about Go: it's basic and doesn't offer anything new or different. Also comparing Go to languages like Javascript is never going to end well because they're entirely different paradigms in almost every category aside the C-like syntax (dynamic vs AOT statically compiled, functional and object orientated vs imperative, loosely typed vs strictly typed, multi-threaded (albeit with green threads) vs single threaded).
- why_Mr_Anderson 6y agoJust from top of my head some of the programming languages I used professionaly in past 30 years - C,C++,C#,F#,Pascal,x86 assembler,D,Java,Javascript. And I still stand behind what I said before - Go is trying to be as different as possible, for no good reason.
- hnlmorg 6y agoWell if you have experience in C and Pascal than really Go shouldn't feel that alien to you. The only thing it brings that differs from them is more verbose error handling, green threads, interfaces and channels. And of them, only the error handling is unique to Go -- everything else is borrowed from other languages.
- rory 6y agoBut it's not really an empty (using the first example) slice because I can have either an empty slice or a nil slice, right? So in Rust or Scala terms, every instance of a type is really an option of that type? It just seems like a totally unnecessary complication to me.