3 ms·
> Why does the Go compiler suddenly care if we provide explicit values now? If the language was self-consistent, it would let me omit both parameters, and just
by unethical_ban 5y ago
> Why does the Go compiler suddenly care if we provide explicit values now? If the language was self-consistent, it would let me omit both parameters, and just default to zero.
Without analyzing the rest of the post (which I read without having the skill to fully comprehend), this stuck out to me.
Perhaps the language behaves one way and not another by design? It's abstraction. By using a Struct, I'm telling the function "don't worry what is in this one box of data, just take it and process it as best you can" while defining two inputs to a function says "I demand that two pieces of data be present".
I don't think it's an inconsistency to see this behavior.
- fasterthanlime 5y agoIt is a very minor point and could easily be removed from the article, but I had that realization while writing those samples and it stuck with me. I really think that if we follow the "zero values by default" philosophy, it wouldn't be shocking for Go to accept omitting function arguments and just zero them. The fact that it doesn't, and insists on you passing the right number of arguments, makes the point that you can't in fact, just afford to zero out everything that isn't explicitly specified.
- arccy 5y agothat's a trade-off with catching user errors, are you more likely to forget to pass an argument or need to pass a zero value?
- myrrlyn 5y agowhy isn't it inconsistent to allow creation of a record with missing components but to deny creation of a stack frame with missing components