Unrelated question. Was going through the scope fu...
# announcements
n
Unrelated question. Was going through the scope functions. They all seem to have a logical niche carved for themselves, with one exception,
with
. It seems like
with
has no real advantage, over the extension function form of
run
. Usually flowcharts/blog posts say "use run if you need ?.
but even if you don't need
?.
, you can just always use
.run` instead of
with
. It seems like it would be preferable if
with
did not exist, so that there would just be fewer scope functions to know with no disadvantage. Am I missing something about
with
?
Like, here's a typical blog post on this topic: https://medium.com/mobile-app-development-publication/mastering-kotlin-standard-functions-run-with-let-also-and-apply-9cd334b0ef84 It mentions this advantage for run over with, but no advantage of with over run
m
The main advantage of
with
is letting you perform a series of calls on an object omitting the receiver
n
@Matteo Mirk run lets you do the same thing though
I'm looking for any reason to use with over run
@Iaroslav Postovalov yeah, i've read that, i don't think it gives you any concrete reasons why with is preferred over run. The examples for with work exactly the same with run as well.
i
@Nir technically, they are equal, however they have different meaning. You may ignore it and use
run
always
n
it seems to me that there are quite a lot of extension functions, and understanding what they all do at a glance isn't trivial.
with
stands out to me as the only one that is totally redundant. So it seems advantageous to have a smaller set of scope functions you have to be familiar with.
More in terms of reading code than writing code
*sorry, quite a lot of scope functions I meant
m
functionality apart, if the words “run” and “with” have the same meaning for you, then go ahead, use whatever you like