Let me make one more concrete suggestion:

On Thu, Mar 17, 2022 at 12:18 AM Alex Besogonov <alex.besogo...@gmail.com>
wrote:

> The real example would look like this:  https://go.dev/play/p/mwUfh4_RBUU
> - you do see why it's a tad problematic?
>

Here is how you could write that, assuming `GetNode` returns a `*Node`:
https://go.dev/play/p/7oGL2F1QgON
It avoids having to write nested conditionals, while also not storing
invalid Nodes in a `Lockable`.

This is just to illustrate that there are sensible middle-grounds, avoiding
storing an invalid `Lockable` in a place where you still have the concrete
type information, while still writing reasonable convenient code.

The point is just that the check for validity should happen *before*
assigning the `Node` to a `Lockable`, not after. If you have to do it in
`store.GetNode` (or file a bug against its owners), because that's where
the assignment happens, then that's where it should happen. If it's
something you do in your code, it should happen at that point.
Find wherever you assign a `Node` to a `Lockable` and insert a check there.
If there are many such places, you can write a helper-function to make it
easier, e.g.
func IsLockable(n *Node) bool { return n != nil && n.BasicNode != nil }

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfHp8fy-k8m49ytPT1%2BAMiciVCXPLE_dFhnBfC9SC4Bc7Q%40mail.gmail.com.

Reply via email to