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
ephemient
11/15/2020, 11:42 AM
you can write
?.get()
ephemient
11/15/2020, 11:45 AM
groovy and coffeescript do have
?[]
but I think it's pretty rare among languages overall
n
Nikky
11/15/2020, 12:00 PM
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
andreasmattsson
11/15/2020, 12:23 PM
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.