Rust VS Go: Traits And Interfaces

preview_player
Показать описание

In the Rust vs Go series, we will investigate which language is best used for certain problems. It is a nice way for beginners to get familiar with certain concepts in both languages. It will help you to pick the right language for the task at hand.

#rustlang #golang
Рекомендации по теме
Комментарии
Автор

FYI the texts are too small to view on a smartphone.

tinnick
Автор

It feels like go was really afraid of naming things "classes".
Because this not explicit association of a method with the struct in many other languages would be explicit class methods, e g.

class Transaction:
def hash(sefl) -> str: ...

With this Python example it does not explicitly tell with which interface does it comply, unless you use some libraries like `zope.interface`

In Rust it explicitly tells which interface the function implements, so it really seems like this enforces the separation of concerns.
When I would like to check - how is the Hasher interface is implemented?
In Go I would need to search by function name, whilst in Rust by the name of the interface, which I think is better - the link between function name and the interface is not explicit.

MurtagBY
Автор

wow that's very cool, one question: if I had another method called doWork() attached to the Transaction struct, so something like this:

func (tx *Transaction) doWork() string {
return "yo"
}

would this still satisfy the Hasher interface, or would it no longer because it has an extra method?

davidalvarez
Автор

With Go, how do you implement a method with the same name for multiple different interfaces in? If for instance you are using two different interfaces (perhaps they both belong to different libraries outside your control for a rename), and the interfaces have a name clash on the method.

LukeFrisken
Автор

Golang seemed so much more readable! Haven’t used much rust personally though

caderosche
Автор

Great video as always!

You've explained very clear similarities between go and rust, can you make a continuation on the differences, please?

I do know that in Rust if you import struct but don't import the trait you won't be able to access the implemented methods.

ThisFiniteWorld
Автор

I feel like an idiot, can someone explain how exactly this saves code? You still have to write the method implementation for every type of struct regardless if you use interfaces/traits.or not...

Jmart
Автор

Processors are developing rapidly. Year by year the area of ​​applications in which the garbage collector is a problem is shrinking.
Rust's only advantage is: safety. But Rust applications are full of vulnerabilities compared to other languages.
I can clearly see that Rust is just a bubble, and that the future is for simpler and easier languages like Go and Zig.

baxiry.