Context Receivers Are Coming to Kotlin!

Context Receivers Are Coming to Kotlin!

Kotlin by JetBrains

2 года назад

37,446 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@hun2579
@hun2579 - 31.10.2023 19:50

Is it kind of DI for function?

Ответить
@user-cm4ce5fh4q
@user-cm4ce5fh4q - 18.10.2023 09:02

good

Ответить
@nymexe
@nymexe - 11.08.2023 15:35

Hmm. After enabling the context receivers feature decompiler is not working. The decompiler is throwing this exception: java.lang.UnsupportedOperationException: Unsupported receiver value: ExampleScope: Ctx { class ContextAppliedClass }

Ответить
@kawthooleidevelopers2864
@kawthooleidevelopers2864 - 20.07.2023 17:33

Is there any comprehensive Kotlin Ktor tutorial that cover advanced topics and best practices? I can only time basic api and basic authentication

Ответить
@khanra17
@khanra17 - 10.03.2023 09:23

Why making kotlin ugly ?

Ответить
@hojjatmashal4823
@hojjatmashal4823 - 07.02.2023 14:23

The most intriguing part to me is how it could replace a great part of a DI framework to decouple our code from a third party DI framework!

Ответить
@kee1o
@kee1o - 29.01.2023 10:46

great explanation

Ответить
@dmytrooleinichenko9865
@dmytrooleinichenko9865 - 12.10.2022 21:22

It is looks like analog of scala implicit/given feature

Ответить
@sheenfabile9460
@sheenfabile9460 - 24.09.2022 12:28

I cant believe this video lenght is 30+ mins. It feels like 5 mins when you get what he is saying. Thanks Sebbbbbbb!

Ответить
@alexanderataman7836
@alexanderataman7836 - 17.09.2022 22:58

Great explained! Thank You! Context replaces the use cases of dependency injection libraries?

Ответить
@tomislavhoman3035
@tomislavhoman3035 - 31.08.2022 19:01

Hmm, seems like it could help making dependency injection to functions when doing functional programming a bit cleaner

Ответить
@user-jw1tb2ec9w
@user-jw1tb2ec9w - 10.08.2022 17:17

How to solve the error?
`The feature "context receivers" is experimental and should be enabled explicitly`

Ответить
@AlbertBikeev
@AlbertBikeev - 24.07.2022 04:09

That's freaking great! Given that you can have generic parameters passed to Context receivers it's practically Typeclasses! Can't wait for it's stabilisation and adoption by library authors!

Ответить
@cularu1
@cularu1 - 12.07.2022 00:42

with() should receive multiple parameters.

Ответить
@udhayarajan_m
@udhayarajan_m - 05.07.2022 13:51

Sorry android Developers we need to escape context too like the one we used with object as `object` and now context as `context`

Ответить
@wusibeaumontmahoney1278
@wusibeaumontmahoney1278 - 29.06.2022 00:34

You are an excellent developer advocate for kotlin, keep up the great work.

Ответить
@renecadenas3610
@renecadenas3610 - 09.06.2022 01:24

It sounds like a kind of Scala feature called "Implicit parameters". But in this case, with too boilerplate. 🤔

Ответить
@akoshollo-szabo1198
@akoshollo-szabo1198 - 17.05.2022 16:58

Some suggestion for the feature: There should be a "with function" with vararg parameters so in case of multiple context we don't have to embed that many times. It would look like with(logger, notification){ ... }. Also in the context function we should be capable to name the contexts like: context(Logger as logger, Notification as notification) or context(logger : Logger, notification : Notification). This would render these boxing interfaces unnecessary. Why isn't this an annotation by the way? Also if there is two interfaces in context(...) and one class implements both, an instance of that class should be enough.

Ответить
@gekylafas
@gekylafas - 07.05.2022 15:18

The EUR + USD example was quite enlightening, kudos!

Ответить
@jameswhitehead74
@jameswhitehead74 - 06.05.2022 00:41

I'm not quite sold on this yet. I'm really struggling to come up with a "real world" use-case for this feature where I wouldn't create a class and use constructor dependency injection instead. Interested to see how this evolves with the community response.

Ответить
@johnokpo4068
@johnokpo4068 - 25.04.2022 02:10

Please 🙏 I have trying to get my app to come up when my phone boots completely but I haven't been able to achieve this, please do you know of any way or material that will help please I will be gland to check it up. Thanks

Ответить
@BrianOxleyTexan
@BrianOxleyTexan - 24.04.2022 17:28

This is one of the best explanations of a complex feature I've run into. Presentation is clear, gives markers to listener to wait for an explanation of a later thing, shows off clear examples in the left hand code sample. Fantastic!

Ответить
@MagnumRocha87
@MagnumRocha87 - 22.04.2022 12:17

wow, this would unblocking a lot of ideas, and clean a lot of code as well 😆
let's go Kotlin 💪

Ответить
@tenminutetokyo2643
@tenminutetokyo2643 - 21.04.2022 22:17

Ah, IKEA.

Ответить
@OlegGolubev_yolo
@OlegGolubev_yolo - 21.04.2022 15:25

Got this in mind for 3 years, glad it coming! :P

Ответить
@islamfaridmadbouly
@islamfaridmadbouly - 20.04.2022 06:15

Great Explanation. Thank you!

Ответить
@a.accioly
@a.accioly - 19.04.2022 19:25

I like where this is going, we definitively need implicit parameters, but... I'm partial to Scala 3 way of doing things. Instead of context() adding a separate argument list + with() changing the scope of "this", Scala 3 added 2 keywords: "given" declares an implicit instance and the keyword "using" is used when implicit parameters are expected (both can be named or anonymous). Of course that Scala being Scala does way more than context receivers, but I l think that their way is a little bit cleaner. As it is, it feels like Kotlin is reusing "with" for something that it really shouldn't be used for.

Ответить
@ryansgot
@ryansgot - 19.04.2022 03:12

The presenter did a good job presenting the topic. However, this feature looks like an attempt to make Kotlin both less readable and less efficient. As a dev manager and tech lead, I can only imagine what atrocities my team will create with this feature. The dependency injection use case makes sense, and the plus infix operator is pretty cool. However, I wonder whether the convenience context receivers provides is worth the cost of the confusion that will result.

Ответить
@skytech2501
@skytech2501 - 18.04.2022 21:09

Kotlin introduces Coroutines to solve "callback hell" and introduces with(), let(), apply() for "callback hell" !!

Ответить
@qbalsdon
@qbalsdon - 18.04.2022 14:50

Thanks for this! I see this as really useful when you need a dependency for ONE method in a class and don't want to inject a new object just for that one method, or don't want to store references in that class. This come with great power, and we all know what comes with great power... great electric bills

Ответить
@user-jz9dm9xr2n
@user-jz9dm9xr2n - 18.04.2022 14:18

Spring framework to every house)

Ответить
@matthewgiallourakis7645
@matthewgiallourakis7645 - 18.04.2022 07:44

Can't wait for this feature to be added to the JS target! This is going to make writing Kotlin DSLs for javascript libraries so much nicer 🙏

Ответить
@christinamariehicks1078
@christinamariehicks1078 - 18.04.2022 04:30

Do no research at all ..lazy bums,.

Ответить
@PhilippLackner
@PhilippLackner - 16.04.2022 22:48

I didn't know I need this

Ответить
@alxjones
@alxjones - 16.04.2022 21:39

This just seems like implicits with extra steps. Why not just implement implicits? What benefit do context receivers have that make them work the extra boilerplate?

Ответить
@senk0n
@senk0n - 16.04.2022 19:44

why dont just: with(firstContext, secondContext) { ... 🤔

Ответить
@vadim-zuev
@vadim-zuev - 16.04.2022 19:13

So "context" is gonna be a keyword and cannot be used as a field name anymore? God help us Android devs...

Ответить
@shumymikaball
@shumymikaball - 16.04.2022 16:05

I would love to see this as a native DI for Kotlin. But needs to improve in some parts.

Ответить
@cryzz0n
@cryzz0n - 16.04.2022 14:49

Thanks for the great introduction to context receivers. Really looking forward to using them in production one day. Great stuff! And thanks to the Kotlin team, they’re doing an amazing job!

Ответить
@cisimon7942
@cisimon7942 - 16.04.2022 10:32

Well explained, thanks Seb. I think I have a couple of ideas on other ways to apply this. Experimentation time, may have to wait for compose to be upgraded to use Kotlin 1.6.20

Ответить
@buszi_
@buszi_ - 16.04.2022 08:05

My feedback at this point:

1. this "context" keyword could be used as a keyword for a function parameter, I think it would be far nicer in the code and we could still use the names of those objects in the code of this function

2. context receivers would be optional, so you could still just pass this context object as a function parameter, this would not force us to use function that uses context receivers within "with" blocks when it is not necessary

3. I don't really like the idea of wrapping everything into interfaces (the problem in the part 2 of this video), why wouldn't we just use named context receivers, so like "context(name: Type)" and then we don't have resolution errors within the function code, I know that it would not let us to call the object as a receiver (so we would need to call "name.foo()" instead of just "foo()") but I would prefer it this way instead of forcing us to wrap everything in additional interfaces

Ответить
@quidryan
@quidryan - 16.04.2022 07:37

Is that a laptop on top of the gray box on top of the bookcase? It's stressing me out 😬.

Ответить
@larsartmann
@larsartmann - 16.04.2022 04:52

Very good video!

Ответить
@kamertonaudiophileplayer847
@kamertonaudiophileplayer847 - 16.04.2022 03:17

Swift.

Ответить
@nickreid4650
@nickreid4650 - 16.04.2022 00:59

I fundamentally disagree with the idea of adding even more anonymous variables.

Ответить
@similartoself4750
@similartoself4750 - 15.04.2022 23:51

Looks promising for DI and DSLs. I think usage outside of those two will most likely lead to horrible code though.

Ответить
@J1oTTa
@J1oTTa - 15.04.2022 23:25

kotlin is love S2

Ответить
@AlanDarkworld
@AlanDarkworld - 15.04.2022 21:09

First of all: very nice and instructive video! I generally like the idea of context receivers, but I can already tell that people will sprinkle them around everywhere for no good reason. What bugs me a little is that we have yet another soft keyword (context) that could have been an annotation. Also, why is it that we don't have to write "::class" after the class name when declaring the context type? Did someone figure out after all that the class name alone might be enough to refer to the class, without needing the rather ugly ::class construct? ;)

Ответить