3 ms·
Your example doesn't compile: https://play.golang.org/p/KQwXqTZHSPF https://play.golang.org/p/KQwXqTZHSPF Go doesn't allow values to just be referenced without
by earthboundkid 7y ago
Your example doesn't compile: https://play.golang.org/p/KQwXqTZHSPF https://play.golang.org/p/KQwXqTZHSPF
Go doesn't allow values to just be referenced without having some use, e.g., JavaScript's `"use strict";` hack could not be done.
In general, I have never seen a bug caused by accidentally ignoring an error. It's a theoretical concern, but not a real world problem.
- stouset 7y agoDon’t know what to tell you, I have personally made this mistake and not had this caught by the compiler. I haven’t used go in several years at this point, so it’s entirely possible this is a newly-caught scenario by the compiler. Regardless, the fundamental point stands. Using tuples to return “meaningless” values alongside errors allows developers to mistakenly use those meaningless values.
- throwaway894345 7y agoI do wish Go would adopt sum types, but in practice errors like you describe are vanishingly rare. It’s mostly a theoretical problem.