3 ms·
Given the following, where is the nil implementation found? package main type FooInterface interface { Baz() } func bar(fizz FooInter
by randomdata 2y ago
Given the following, where is the nil implementation found?
package main
type FooInterface interface {
Baz()
}
func bar(fizz FooInterface) {
bizz.Baz()
}
type MyFoo struct{}
func (*MyFoo) Baz() {}
func main() {
var foo FooInterface = &MyFoo{}
bar(foo)
}
- Dylan16807 2y agoNil is built-in. You just have to write the code to instantiate it and the compiler gives you one. The coder does not need to create an implementation, it's there for free. I would not have called it a "second implementation" myself, but that's your claim to defend, not mine.
- randomdata 2y agomap is also built-in. Where do you find the hash map in the given program? By your logic some nebulous package in a random GitHub repository that happens to satisfy an interface is also another implementation, but you would have to be completely out to lunch to think that fits with the topic of discussion.
- Dylan16807 2y ago> map is also built-in. Where do you find the hash map in the given program? If you told me a type can be optimized because the compiler knows it can only have non-hash-map uses, but I could put that type into a hash map with a single line, I think I would be right to be skeptical. > By your logic some nebulous package in a GitHub repository that happens to satisfy an interface is also another implementation, but you would have to be completely out to lunch to think that fits with the topic of discussion. I expect the compiler to have a list of implementations somewhere. I don't know if I can expect it to track if nil is ever used with an interface. I could believe the optimization exists with the right analysis setup but you called the idea of finding a citation a "waste of time" so that's not very convincing.
- randomdata 2y ago> but you called the idea of finding a citation a "waste of time" so that's not very convincing. Not only a waste of time, but straight up illogical. If one wants to have a discussion with someone else, they can go to that someone else. There is no logical reason for me to be a pointless middleman even if time were infinite. Now, as fun as that tangent was, where is the nil implementation and hash map found in the given program?
- Dylan16807 2y agoThe implementation is preexisting. Even if it was directly used, there would not be an implementation in the snippet. So it not being implemented in the snippet proves nothing. And what do you mean "someone else"? You're the one that said the compiler "certainly knows" how to do that.
- randomdata 2y ago> So it not being implemented in the snippet proves nothing. It doesn't prove anything, but is what we've been talking about. Indeed, there is nothing to prove. Never was. What is it with this weird obsession you have with being convinced by something? Nobody was ever trying to convince you of anything, nor would there be any reason to ever try to. That would be a pointless endeavour. > And what do you mean "someone else"? He who wrote the "citation".
- Dylan16807 2y ago> there is nothing to prove. Never was. What was the point of your question, if not to prove something? If you were trying to imply that the implementation doesn't exist, that implication was fatally flawed. If you were asking to waste time, then it worked. If you had another motive, what was it? Are we having a 5d chess game? I thought it was a normal conversation. > He who wrote the "citation". Nobody? Nobody wrote a citation. Do you mean the person that asked for a citation? If so, you're wrong. Finding evidence for your own claims would not make you a middleman. They didn't want to have a discussion with someone else, they wanted a discussion with you, and for that discussion to have evidence. Citing evidence is not passing the buck to someone else, it's an important part of making claims.