-
... tausend Zeilen umfassende Funktion
Autor: MrTridac 03.11.23 - 15:11
Ok, verstehe ich das richtig:
Der Treiber ist schlecht weil er aufgeblasene Funktionen enthält und daran ist die Programmiersprache schuld?
Wenn eine Funktion 1000 Zeilen hat, ist das in jeder Programmiersprache schlecht, auch in Rust.
Rust vor C zu stellen weil jemand Murks programmiert, ist verlogen. -
Re: ... tausend Zeilen umfassende Funktion
Autor: Saladino 03.11.23 - 16:08
Nein Google will die Treiber zukünftig in Rust schreiben, da dort das Speicher und Typenmanagement einfacher ist.
Der hier im Artikel genannte Treiber ist nun der Erste, der in Rust umgesetzt wurde.
Dabei haben sie auch den Code optimiert, unter anderem eben die 1000 Zeilen Funktion.
Dass die Funktion davor nicht angegangen wurde kennt man ja, da ist nie Geld da. -
Re: ... tausend Zeilen umfassende Funktion
Autor: oleid 03.11.23 - 16:41
> Die Nutzung von Rust verhindere dabei typische Probleme aus C und das Typsystem helfe im Umgang mit verschiedenen Pointern. Auch der Umgang mit Fehlern sei unter Rust besser
Die einzige Metaprogrammierung, die du in C hast ist halt der Präprozessor. In rust kommt ein ausdrucksstärkeres Typsystem dazu und auch eine Makrosprache, die um Längen besser ist als ein reiner Präprozessor. Damit kann man insgesamt auf einer höheren Abstraktionsschicht arbeiten bei ähnlicher Geschwindigkeit des generierten Binärcodes. -
Re: ... tausend Zeilen umfassende Funktion
Autor: Steffo 03.11.23 - 21:47
https://lore.kernel.org/lkml/20231101-rust-binder-v1-0-08ba9197f637@google.com/
We decided to use Rust because it directly addresses a number of the
challenges within Binder that we have faced during the last years. It
prevents mistakes with ref counting, locking, bounds checking, and also
does a lot to reduce the complexity of error handling. Additionally,
we've been able to use the more expressive type system to encode the
ownership semantics of the various structs and pointers, which takes the
complexity of managing object lifetimes out of the hands of the
programmer, reducing the risk of use-after-frees and similar problems.
Rust has many different pointer types that it uses to encode ownership
semantics into the type system, and this is probably one of the most
important aspects of how it helps in Binder. The Binder driver has a lot
of different objects that have complex ownership semantics; some
pointers own a refcount, some pointers have exclusive ownership, and
some pointers just reference the object and it is kept alive in some
other manner. With Rust, we can use a different pointer type for each
kind of pointer, which enables the compiler to enforce that the
ownership semantics are implemented correctly.
Another useful feature is Rust's error handling. Rust allows for more
simplified error handling with features such as destructors, and you get
compilation failures if errors are not properly handled. This means that
even though Rust requires you to spend more lines of code than C on
things such as writing down invariants that are left implicit in C, the
Rust driver is still slightly smaller than C binder: Rust is 5.5kLOC and
C is 5.8kLOC. (These numbers are excluding blank lines, comments,
binderfs, and any debugging facilities in C that are not yet implemented
in the Rust driver. The numbers include abstractions in rust/kernel/
that are unlikely to be used by other drivers than Binder.)
2 mal bearbeitet, zuletzt am 03.11.23 21:47 durch Steffo.



