Abolishing Kotlin Context Receivers <https://youtu...
# feed
d
Abolishing Kotlin Context Receivers

https://youtu.be/W_Hd1O3_XUk

👍 3
d
I'm curious why when removing IO you didn't feel using search/replace was the best approach? I feel like it would have taken a fraction of the time.
d
Thanks for the interesting question. In retrospect perhaps it would have been quicker, but then, with the issues of function type compatibility that came out, maybe I would have just spent a long stressful time trying to work out what a compile issue was without the context of a small change that must be responsible? Another reason is that I know I have another context receiver to address, and there I actually want to pass a value, making search and replace a lot less simple. So this time I’m learning lessons that will help me in the next episode.
d
Okay. Makes sense.
d
It makes me realise how much I favour small reversible steps towards a goal over sweeping changes that I have to think about. I think it may be an age thing!
d
I think generally that's a good idea. I tend to think in "atomic operations", as well. For removing the context(IO) from everywhere, my first instinct would be a regex-replace of the form
context\((.**?,\s*)*IO(\s*,.*?)**
to
context($1$2)
, followed by
context()
to blank. If that didn't compile and pass tests, then I would resort to the approach you took.
For the other context receivers though, almost certainly need more thoughtful action and smaller changes.
d
My initial hunch was based on it taking maybe 5 minutes to come up with a regex that good (I have a blind spot), and a 95% chance of it not working when I did.
d
Got it.