Rust Does Interfaces BETTER!

preview_player
Показать описание
Comparing Rust's traits over with interfaces from languages like Java, and showing off the advantages that the traits offer.

Linked article:
Рекомендации по теме
Комментарии
Автор

Every now and then, the youtube algorithm turns up a gem. Solid video, dude!

SolarShado
Автор

Great video and explanations! So much knowledge baked into a 10 min video! I also code primarily in Java, so this kind of videos are exceptionally interesting to me!

programming
Автор

For being one of your first videos this is pretty good. You seem to be talented. Wish you all the best for your channel!

rene
Автор

Something that would've made this video better for me would be slightly less pausing during speech. On one hand it's very clear and proper, but I would've been able to pay attention more easily if the speech flowed better through shorter pauses.
It's fine to take longer pauses, but it felt a bit too frequent. Long pauses are more effective when used sparsely.

Good video though, a nice showcase.

CottidaeSEA
Автор

Nice video man! Sometimes we have to hear it from the other person to really understand some things. You made me realize why I like trait system so much in Rust!
As some people mentioned - if you'll work on your speaking you'll do great on YouTube!

Dywanoid
Автор

Nice video, you have a clear explanation and a clear voice. it is perfect for non native english like me

ikhlasulkamal
Автор

If you want to the contents of the video in text form, here's the corresponding article:
Errata:

This is mostly a showcase of the basic syntax features that I think Rust does better around interfaces. At the start, the video is framed as a straight-up comparison, which it isn't for the most part - aspects of how Java tackles the limitations of its basic syntax around this are not covered.

As mentioned by @tauraamui, the Intro slide mentions that in Rust, data is decoupled from behavior while this is not the case in Java - this is incorrect, as most idiomatic Rust has a lot of methods associated to structs. The methods are not defined in the struct itself, but they are still paired / coupled with the struct.

At around 4:00 the code should be:

fn next(&mut self) -> Option<Self::Item>{ // instead of ";"
Some(Thing {...})
}

(the semicolon needs to be replaced with an opening curly brace)

TrustyBits
Автор

This was a really cool video! Helped some things 'click' in my mind finally which for some reason they never fully did. Thanks and keep up the good work! ^^

friendliness
Автор

Hey I liked the video, but at around 4 minutes in (4:00) when you define the impl for the Iterator trait, I think there might be a typo (there's a ; where a { should be). shouldn't it be:

fn next(&mut self) -> Option<Self::Item>{ // instead of a ;
Some(Thing {...})
}

Not a huge deal of course, but since I am trying to learn Rust I was scratching my head for a bit wondering if Rust just has some weird syntax when defining interface implementations 😅

patrickwoolard
Автор

most of the points here can be disputed:
- java does not force you to program in OOP way, sure you can, it was intended to, but coding in FP style is not as "ugly" as some may think
- java also allows "derive(Eq)" annotations on objects using comptime libs, same number of lines of code
- for the life of me, i cannot think of benefit of "impl Trait for SomeStruct {}" over "class MySubClass extends SomeStruct implements Trait"
- function signature can also immediately tell you what is mutated and what is not in java:
doStuff(Map<String, String> m);
vs
doStuff(ImmutableMap<String, String> m);
also, if you REALLY want to know whether method modifies state of its own object (which you don't actually need to know if you didn't implement the class), why not annotate with some docstring? every modern editor will show you hints
agreeable points:
- method dispatching is fair point. obviously, rust is faster language, no debate about it but from the perspective of a developer doesn't affect ergonomics of coding

bernardcrnkovic
Автор

Good video but could be a bit faster paced. Just cutting a bit of the dead air.

gusvanwes
Автор

2:31 would it be possible in java to create a sub class for an external class, and have that sub class implement the target interface? i think thats a work-around to have an object in an external library implement an interface, kind of like a decorator. this, however, is gross af and it looks much muuuch nicer to do in rust

pepperplume
Автор

This was a great video! It really helped me crystallize some things in my head. Thank you for making it, subscribed :)

JaLikon
Автор

Methods on a struct is coupling logic with data, what do you mean it's uncoupled in Rust?

tauraamui
Автор

8:28 Does Java's or Rust's approach require more instructions on the JVM?

charliesumorok
Автор

C# and Kotlin have extension functions that allow you to superimpose a functionality over libraries you don't own. Likewise, type Item can be easily implemented via generics.

ibrahimkoz
Автор

Indeed, it's a good illustration of a power of traits in Rust.

kamertonaudiophileplayer
Автор

Not sure, what's the thing. Doing Kotlin instead Java - which is 100% interoperable has also extensions and multiple stuff in 1 file.
From "clean code" point of view, not sure if traits instead interfaces make code easier to understand at all. At least you'd have to rethink the gang-of-four patterns, otherwise it just introduces randomness ("hey look at my crazy code tricks to scramble the meaning")

zyklos
Автор

Is there a tool that you use for creating these slides?🤔 Will be really helpful for college grads.

anuragdhadse
Автор

Thank you. Great explanation!
However, @ 5:30, that is wrong. Java has static methods which is the exact equivalent of that. Instead of being specified in the argument, whether or not it can use the self/this, can be seen in by looking at the "static" keyword in the signature.

brunoais