Self-Types in Scala - the Why and the How | Rock the JVM

  Рет қаралды 7,665

Rock the JVM

Rock the JVM

Күн бұрын

Пікірлер: 35
@jmhimara
@jmhimara 2 жыл бұрын
This is a great example of one of the fundamental weaknesses of the OOP paradigm, and something that is bound to get exponentially worse as the domain logic gets larger and more complex. IMO, neither option really solves the problem in a satisfactory method -- admittedly, self-types are an elegant approach, albeit still just a Band-Aid to the larger problem.
@megadethjohn
@megadethjohn 4 жыл бұрын
Great video! One of the more concise and informative explanations of self types out there.
@rockthejvm
@rockthejvm 4 жыл бұрын
Glad you liked it!
@jeanfdmelo
@jeanfdmelo 4 жыл бұрын
Keep videos coming, Daniel! That's gold!
@rockthejvm
@rockthejvm 4 жыл бұрын
Thanks! Share with whoever you think might find it useful!
@pbawa2003
@pbawa2003 2 жыл бұрын
Really well explained about self types and difference from inheritance using trait extensions
@XINClover
@XINClover 3 жыл бұрын
Very clearly explained. I learn new things every day. Thank you Daniel!
@sergeibatiuk3468
@sergeibatiuk3468 Жыл бұрын
Nice! But can you use this pattern (the Cake pattern?) to compose classes or is it for traits only?
@mompyish
@mompyish 3 жыл бұрын
This is awesome!!.. I have been struggling to find out the meaning of this syntax in one of libraries..Blogs and article did't help.Thanks Daniel
@rockthejvm
@rockthejvm 3 жыл бұрын
Glad it was helpful!
@nilanjansarkar100
@nilanjansarkar100 2 жыл бұрын
Daniel, you rock man! This explains things so clearly!
@rheafernandeshallu
@rheafernandeshallu 4 жыл бұрын
Thank you again :) It's really helping me get better at writing code.
@rockthejvm
@rockthejvm 4 жыл бұрын
That's my goal!
@harishgontu9285
@harishgontu9285 4 жыл бұрын
Nice !! You should join Leo Benkel scala server. It is a place where they try to encourage budding scala devs
@ddosia1313
@ddosia1313 Жыл бұрын
Amazing video, thx!
@tai-hao-le
@tai-hao-le 3 жыл бұрын
great video but I am still a bit confused about the difference between self-types and inheritance. do you have any additional resources to research this subject? thanks!
@rockthejvm
@rockthejvm 3 жыл бұрын
How are you confused? Maybe I can help here.
@egorkovesh5033
@egorkovesh5033 3 жыл бұрын
13:11 people constantly ask me "WHAT THE F...undamental diffrence..."
@Jankoekepannekoek
@Jankoekepannekoek 4 жыл бұрын
I use this mechanism often to access a reference to an outer class when I'm creating inner classes, since in Scala you can't say 'MyOuterClass.this' like you can in Java.
@rockthejvm
@rockthejvm 4 жыл бұрын
Yep!
@StefanReich
@StefanReich 3 жыл бұрын
Couldn't you simply put a field of type Person into the Diet trait?
@rockthejvm
@rockthejvm 3 жыл бұрын
As always, there are multiple solutions to the same problem.
@sergeibatiuk3468
@sergeibatiuk3468 Жыл бұрын
@@rockthejvm But what are the pros and cons of both?
@avinashc6114
@avinashc6114 3 жыл бұрын
It's clear thank you 🔥
@rockthejvm
@rockthejvm 3 жыл бұрын
That's my goal!
@romanburenko7593
@romanburenko7593 3 жыл бұрын
Great explanation! Thanks a lot!
@rockthejvm
@rockthejvm 3 жыл бұрын
Glad you liked it!
@elgireth
@elgireth 4 жыл бұрын
Key difference is that self type can be generic, which is used in F-Bounded polymorphism.
@rockthejvm
@rockthejvm 4 жыл бұрын
F-bounded polymorphism is something else. It can be used in conjunction with self-types, but that's not the defining difference between self-types and inheritance.
@DevInsideYou
@DevInsideYou 4 жыл бұрын
Why not just add person to eat? def eat(thing: Edible, person: Person): Boolean
@rockthejvm
@rockthejvm 4 жыл бұрын
This would be very similar to the extension option #1, because we bleed API dependencies from one type to the other.
@moy2010
@moy2010 3 жыл бұрын
What about an associated type? It seems to me that it achieves exactly the same as the self type, dunno why they needed to add yet another way to express the same.
@rockthejvm
@rockthejvm 3 жыл бұрын
What do you mean by associated type?
@moy2010
@moy2010 3 жыл бұрын
@@rockthejvm I found that they are called "Abstract types" in Scala, and seems that this discussion has already been done in StackOverflow: stackoverflow.com/questions/1154571/scala-abstract-types-vs-generics
@rockthejvm
@rockthejvm 3 жыл бұрын
@@moy2010 you mean abstract type members. These are different than self-types and they serve a different purpose.
How to Write Controllable Futures in Scala | Rock the JVM
12:04
Rock the JVM
Рет қаралды 11 М.
Value Classes in Scala | Rock the JVM
22:27
Rock the JVM
Рет қаралды 5 М.
World’s strongest WOMAN vs regular GIRLS
00:56
A4
Рет қаралды 39 МЛН
ТЮРЕМЩИК В БОКСЕ! #shorts
00:58
HARD_MMA
Рет қаралды 2,2 МЛН
ТЫ В ДЕТСТВЕ КОГДА ВЫПАЛ ЗУБ😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 3,7 МЛН
What the Functor? | Functors in Scala | Rock the JVM
24:43
Rock the JVM
Рет қаралды 12 М.
Sync, Async, Blocking and Non-Blocking | Rock the JVM
16:19
Rock the JVM
Рет қаралды 12 М.
Types, Kinds and Type Constructors in Scala | Rock the JVM
17:53
Rock the JVM
Рет қаралды 6 М.
What Can Scala Learn from Rust? by John A. De Goes
59:03
Ziverge
Рет қаралды 11 М.
Objects and Companions in Scala | Rock the JVM
14:01
Rock the JVM
Рет қаралды 9 М.
Algebraic Data Types (ADT) in Scala | Rock the JVM
14:19
Rock the JVM
Рет қаралды 10 М.
Semigroups and Monoids in Scala
23:05
Rock the JVM
Рет қаралды 6 М.
Given and Using Clauses in Scala 3 | Rock the JVM
20:24
Rock the JVM
Рет қаралды 6 М.
Scala: Beyond the basics with Christopher Batey
48:05
Devoxx
Рет қаралды 48 М.
Idiomatic Error Handling in Scala | Rock the JVM
26:45
Rock the JVM
Рет қаралды 9 М.