Kotlin & Functional Programming: pick the best, skip the rest by Urs Peter

  Рет қаралды 26,817

Kotlin by JetBrains

Kotlin by JetBrains

Күн бұрын

Пікірлер: 31
@GakisStylianos
@GakisStylianos Жыл бұрын
Arrow + coroutines + null types what a great combination! It really feels like the pieces have all fallen together to give us this super convenient developer experience.
@Z1ew-k1q
@Z1ew-k1q Жыл бұрын
why nulls? how is it better
@GakisStylianos
@GakisStylianos Жыл бұрын
@@Z1ew-k1q Sorry what I should've written instead was "Typed nullability". The fact that the type itself can provide us with information about whether something can be null or not. Basically what helps us not have to use `Optional`.
@KyleSmithNH
@KyleSmithNH Жыл бұрын
@@GakisStylianos Kotlin has typed nulls `T` vs `T?`, but they aren't monadic (e.g., you can't map them).
@iamrigank
@iamrigank Жыл бұрын
Overtime I have naturally shifted from an imperative style programming to a more expressive style through the composable artifacts that Kotlin natively offers and I have seen improvements in code readability, maintainability, pace and a better “way” of approaching code. But to my dismay, I have never been able to explain to my coworkers why such a shift in style improves code and what actually is fundamentally different about the two approaches. As this speaker presumed, the mathematical labeling, like monoids, has always confused me. I am so grateful of this beautiful talk as it now makes me able (I feel) to explain to others the benefits of say, higher order scoping functions and why & when to use them, and when not to. Great presentation. Thank you!
@philnguyen0112
@philnguyen0112 Жыл бұрын
I agree with this talk that many FP techniques aren’t applicable in Kotlin, appreciate the well-prepared examples and visualizations, and acknowledge that the speaker offers some practical insights (e.g. “good code should reflect domain”). But this talk sends the wrong message, and spreads misinformation on multiple levels. First, the talk mentions “best” and “rest” as if they were inherent in functional programming. What needs to be clear (even with the obvious context that this is a Kotlin conference) is that “best” here means “which Kotlin can express”, and “rest” means “which Kotlin doesn’t have the abstraction power for”. Like any language, Kotlin comes with tradeoffs (Whether the trade-offs are reasonable or informed is a separate discussion). The problem with trying to express an idea in a language without the abstraction power for it is that it becomes a pattern, or even an encoding: instead of being named once and instantiated for uses, it comes with boilerplates that only make sense to people who already know what it’s about. As the speaker remarks, the noise can quickly crowd out the signals. Expressing monads in a language without higher-kinded types is cumbersome, because the interface cannot be programmatically stated once and enforced elsewhere. (The higher-kinded types “language feature” is not a complexity, at least to the programmer. It’s a simplification that generalizes and unifies existing understanding, similar to how one accepts negative numbers in grade-school math, or higher-order functions in programming. The complexity coming from the lack of higher-kinded types isn’t a sign that monads are inherently impractical as a programming concept; it simply means they aren’t a good trade off in some languages, which should be made clear). Kotlin’s design seems to be about throwing in ad-hoc language features to address specific needs (e.g. nullable, `suspend`, `@Composable`) instead of having a small core that generalizes well. This talk is about informing the audience of idiomatic Kotlin when it works well for their use cases, and practical compromises when it doesn’t. Second, the monad explanation is wrong, because the speaker tries to make sense of “A monad is a monoid…” without having ever picked up category theory. This is a ChatGPT-level BS "explanation". The “monoid” discussed in the talk is the more specific and well established classic “monoid on sets”, from abstract algebra, which predates category theory. The “monoid” from category theory is short for “monoid object in monoidal category” (look it up), which is a vast generalization. When it’s a monoid in the category where objects are sets and arrows are functions, you recover classic monoid. When it’s a monoid in the category where objects are endofunctors and arrows are natural transformations, you get a monad. CLASSIC MONOID CANNOT BE USED TO EXPLAIN MONAD AS A SPECIAL CASE; it’s at best an analogy. The `empty` and `combine` operations discussed are not at all part of a monad’s definition. If you want an analogy with classic monoid, the associative `combine` is analogous to the fact that if you have a triply-nested monad `m`, then using `join` to collapse it would result in the same `m` whether you collapse the outer nesting or the inner nesting first. And the `empty` in classic monoid is analogous to the `pure` operation in monad where you inject a value into an effect-free monadic action, which the speaker completely omitted when describing monad. Finally, it’s worth noting that “A monad is a monoid in the category of endofunctors” originates from the joking blog post “A brief, incomplete, and mostly wrong history of programming languages”: It wasn’t used by any computer scientist as a serious explanation to programmers. In fact, bringing up category theory’s monoid is not at all a practical way to explain monads to programmers, which the joke is about. Third, this talk is plagued with name-dropping (e.g. “semi-group”) and brief nonsensical statements (e.g. “monoid extends applicative, …, there’s also small nuances, but for now, …”), seemingly to project the image that the speaker has studied these topics extensively and is now in the position to distill things for the audience. The comment “Monad transformers are kind of a dirty trick” is particularly odd. Monad transformers have problems, but they are a generalization to make monads composable, not a hack that only “works for two levels” (???). Higher-kinded types are central to expressing monads (in a typed language, at least), but here it is brought up as a specific language feature to enable comprehension syntax, which is a really weird discussion. While this talk has practical tips and takeaways relevant to Kotlin, the statements on more general topics are either wrong or too vague to refute. The speaker appears to suggest that he has been anywhere near “the mountain peak” (whatever that is) and is coming back to give insightful “functional common sense” advice, but I’m not convinced he’s picked up any category theory, or any other mathematics underlying programming and abstractions. This could have been a decent talk had it been framed as “what’s sensible for Kotlin”, as opposed to “what’s sane and what’s not from functional programming”.
@GregoryMatous
@GregoryMatous Жыл бұрын
>> In fact, bringing up category theory’s monoid is not at all a practical way to explain monads to programmers, which the joke is about. too funny! and spot on
@i-am-the-slime
@i-am-the-slime 9 ай бұрын
Thank you. This might just be the best comment I've ever read on KZbin.
@PairingWithDuncan
@PairingWithDuncan Жыл бұрын
One of my favourites from the conference. Up until recently Arrow has felt like a different world than Kotlin, but it’s great to see that it is finding the sweet spot of working with the language.
@sabinbajracharya3815
@sabinbajracharya3815 Жыл бұрын
At around 4:33 (Imperative Programming vs Expression Oriented programming), the imperative style is doing many different task to find the best dev. Normally one would or could do the following (by breaking down different sub task into its own function. ) fun findBestDev(lang: String): Developer? { try { val devs = client.getAll() val filteredDevs = filterByLanguage(devs) maxByExperience(filteredDevs) } catch (ex: Exception) { null } Note: The "filterByLanguage" can be made more reusable. eg: filterBy(list, comparator) and same goes for "maxByExperience" Doing this way, from my perspective, the code is easier to read (even for beginners) than the one with expression oriented programming. My personal experience with RxJava was nightmare with lots of methods chained together. It made it easy for the person actually doing the coding but was nightmare for the third person to understand the code by just looking at it.
@artemsokolov5007
@artemsokolov5007 Жыл бұрын
> was nightmare for the third person to understand the code by just looking at it. SKILL ISSUE
@tonnoztech
@tonnoztech Жыл бұрын
One of the very best talk out there about Kotlin and FP, hands down. Just a small note: Result doesn't offer .flatMap out of the box without the help of Arrow core helper functions.
@torstenwelches9394
@torstenwelches9394 11 ай бұрын
Not sure how the video chapters came to life (AI?), but "Monads" and "Monad comprehension" are shown as "Monets" and "Monet comprehension" for me... 😄 And at 30:20 I believe with context receivers the bind() calls would also get obsolete since the other functions like getDevByName would most likely be callable with the same EffectScope context, no? Great talk!!
@vasigorc
@vasigorc Жыл бұрын
Very biased opinion, FP seems incomplete without HKT and the Tagless Final pattern. There'll be just a lot manual hooks here and there.
@117masterxbox
@117masterxbox 11 ай бұрын
In the example about the scope functions at 07:50 I find it actually much more difficult to read. One main drawback is that the code is getting very nested.
@manikantareddy7595
@manikantareddy7595 Жыл бұрын
13:24 periodic table in chemistry right ? Great talk though thoroughly enjoyed
@eskii2
@eskii2 8 ай бұрын
What is FP wo monad do syntax?
@tobiasbrenner7176
@tobiasbrenner7176 7 ай бұрын
Awesome Talk. Thank you a lot
@TJ-hs1qm
@TJ-hs1qm 11 ай бұрын
FP is different from OO, not saying OO is bad, but you have to put some time in re-wiring your way of thinking, blaming another language is unfortunate. So far, I have seen nothing that couldn't be done with ease in vanilla Scala with less ceremony. Future has its own error channel in Scala as well and nesting monads are a sign of generally bad programming. Either[Optional] for ex. can be modeled as domain specific type with 3 cases but more likely is Either redundant. Keep monads at the outer fringes of the application. And a better way to layer your app is vertically not horizontally benefiting from functional composition as illustrated here Scott Wlaschin - Designing with capabilities kzbin.info/www/bejne/iKLPn4qsa7ONpdU And if you need the ? operator, it can be implemented in Scala 3 as well.
@andmal8
@andmal8 Жыл бұрын
Great talk!
@ihobychristian2065
@ihobychristian2065 Жыл бұрын
It really pointed out how relevant functional programming is
@i-am-the-slime
@i-am-the-slime 9 ай бұрын
Xebia Functional is pretty much dead now, right?
@NemiriNabil
@NemiriNabil 4 ай бұрын
best lecture
@sevarbg83
@sevarbg83 5 ай бұрын
Cool! Now we only need to teach business people how *not* to think in imperative, they always think in terms of mutation procedures. :D
@jesprotech
@jesprotech Жыл бұрын
Arrow optics is great when working with gradle 42:11 , but I have my doubts about using it with maven which is still much more popular for backend services. So far I’m using the Dyescape plugin in my experimental projects and their team has been excellent in providing support, but Kotlin still updates faster than what they can keep up to. This poses a problem to many non-android based companies that use maven.
@baer126
@baer126 7 ай бұрын
I wanted to learn kotlin, do I need to learn Java?
@timj11dude
@timj11dude 7 ай бұрын
Nope, you'll see plenty of references to javain the tutorials, and many guides are written on the basis of an existing java dev learning kotlin, but there are pure beginner tutorials out there.
@Das.Kleine.Krokodil
@Das.Kleine.Krokodil Жыл бұрын
17:50
@pookiepats
@pookiepats 25 күн бұрын
when you go dev rel way too soon and just stay there forever.
@no-bias-
@no-bias- 9 ай бұрын
this presentation is the best!
@leorandomnickname
@leorandomnickname 10 ай бұрын
great talk
You can do desktop too! by Victor Kropp
37:29
Kotlin by JetBrains
Рет қаралды 12 М.
Headache-Free Reactive Programming With Spring Boot and Kotlin Coroutines
54:21
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
Coroutines and Loom behind the scenes by Roman Elizarov
45:22
Kotlin by JetBrains
Рет қаралды 34 М.
Functional Programming in 40 Minutes • Russ Olsen • GOTO 2018
41:35
GOTO Conferences
Рет қаралды 821 М.
Advanced Kotlin: Generics, Type Erasure, and Reflection Explained
23:00
Functional Design Patterns - Scott Wlaschin
1:05:50
NDC Conferences
Рет қаралды 301 М.
Modern Compose Architecture with Circuit by Zac Sweers and Kieran Elliott
30:49
Creating The Best Programming Language: The Story of Kotlin
21:30
Kotlin by JetBrains
Рет қаралды 34 М.
Arrow 2.0's Trajectory by Simon Vergauwen
33:29
Kotlin by JetBrains
Рет қаралды 6 М.