yazgoo / umberwm

:ram: a minimalistic X window manager based on tinywm, inspired by qtile.
57 stars 3 forks source link

Reduce indentation #23

Closed mfdorst closed 3 years ago

mfdorst commented 3 years ago

Move some deeply nested code out into dedicated functions, such as handle_key_press(), handle_button_press(), resize_bsp() and resize_monocle(). This makes a lot of logic easier to follow, and also reduces indentation several levels.

Replace single arm match statements with if let, e.g.:

match x {
    Some(y) => do_something(y),
    None => None
}

becomes

if let Some(y) = x {
    do_something(y);
}

This removes a level of indentation.

Replace let _ = x with x.ok(). No reason for this other than I think it looks better.

This PR supersedes #21 (it is based on top of the edits in that PR).

yazgoo commented 3 years ago

Thanks for your contribution. Do you know if there is a way to check formatting at compile time ?

mfdorst commented 3 years ago

@yazgoo you mean other than running cargo fmt? Not that I'm aware of, but there might be. Perhaps you can add a hook to cargo build? If you're interested in ensuring that PRs to this repo are formatted properly you can use CI to do that. https://github.com/rust-lang/rustfmt#checking-style-on-a-ci-server