Hacker News new | ask | show | jobs
by janderland 842 days ago
Check it once and type cast it before passing it down the call stack. If you need a polymorphic type all the way down then model it using structs and interfaces so that the required operations are always available as methods. It’s the same as other languages which lack optionals/narrowing: C/C++, Java, etc.
2 comments

sorry, type cast it to what?

Say i have `*Thing`. Are you saying i should cast it to a `Thing`? That is what I was doing initially (im fine with copies), but then you can't call functions that mutate.

C++ and Java both have some form of Optional btw.
Yes, but in both it's not really mainstream.