ruma / homeserver

A Matrix homeserver written in Rust.
https://www.ruma.io/
1.08k stars 41 forks source link

Spliting Room::create() into small functions #156

Open farodin91 opened 7 years ago

farodin91 commented 7 years ago

Room::create is more than 350 lines of code. This helps make it easier to fix bugs in the function.

mujx commented 7 years ago

That's true but it's easy code; most of the lines are declarations of event structs. The biggest part of the function is the pattern matching on initial state which cannot be split (maybe a new function?). The only improvement I see is to remove the flags is_something_set and just generate the events in the order specified by the spec. That will generate a few extra events that will be overwritten; that's why the flags exist.

farodin91 commented 7 years ago

I think of the following if creation_options.initial_state.is_some() {.

farodin91 commented 7 years ago

Moving part in into private function would help reduce doubling, but make it much easier to read since every function has a name and a small doc.