would be cool to have nullsafe operator variants.....
# announcements
n
would be cool to have nullsafe operator variants.. especially for
get
.. would avoid some ugly hacks with
let
or assigning intermediary variables not sure if that would promote writing worse code and longer nullsafe call chains..
e
you can write
?.get()
groovy and coffeescript do have
?[]
but I think it's pretty rare among languages overall
n
i realize i can.. but it is quite annoying that i have
[key]
and
?.get(key)
sometimes in the same line or function and the only difference is nullability of the receiver it just takes some time to get used to reading code like that i guess.. or always using
get
over
[]
a
My habit is to always use
get
when chaining multiple operations (regardless of nullability). And honestly for all operators (e.g.
plus(x)
over
+
etc), only using the operator form for trivial statements. Probably a matter of taste but that's what I've found most readable and is a simple rule of thumb to follow.
👍 2