Is it better to use `variable?.let{...}` or `if (v...
# announcements
o
Is it better to use
variable?.let{...}
or
if (variable != null) {...}
?
g
if
variable
is a local stack variable, I'd go with option 2 since its brain dead. If
variable
is a field, option 1 is more elegant
o
sorry, I don't understand what "brain dead" means in this context
care to explain?
g
any programmer from a C-like language is going to know what
if(x != null){ doStuff(x) }
means
?.let {
is simply a kotlin-specific thing, ergo you need to be more comfortable with the language to understand it
👍 1