As we know, functions return values while procedures don't. That's basically the difference.
I've renamed procedures in my crates as title suggests and it seems there are some improvements in readability.
Below are some code chunks:
fn main() {
let terminate = Arc::new(AtomicBool::default());
_register_signal_handling_(&terminate);
let conn = swayipc::Connection::new()
.expect("Cannot connect to Sway!");
let mut libinput = Libinput::new_from_path(Interface);
let args = get_arguments();
let pointer_device = libinput
.path_add_device(&args.device_path)
.expect("Cannot open pointer device");
handle_events(conn, libinput, terminate, pointer_device, args)
.unwrap()
}
#[tokio::main(worker_threads=2)]
async fn main() {
_init_logger_();
let env_ctx = context::gather_env::enter();
_warn_if_incompatible_options_(&env_ctx.opt);
validate_files(env_ctx).await;
}
async fn connect_neovim(cli_ctx: context::UsageContext) {
log::info!(target: "context", "{cli_ctx:#?}");
_init_panic_hook_();
let mut nvim_conn = connection::open(
&cli_ctx.tmp_dir,
&cli_ctx.page_id,
&cli_ctx.opt.address,
&cli_ctx.opt.config,
&cli_ctx.opt.config,
cli_ctx.print_protection
).await;
let mut nvim_ctx = context::connect_neovim::enter(cli_ctx);
if nvim_conn.nvim_proc.is_some() {
nvim_ctx
.child_neovim_process_has_been_spawned()
}
manage_page_state(&mut nvim_conn, nvim_ctx).await
}
In all chunks last function calls in main function are technically procedures, but since they're continuation of main function I've decided to keep their names as is. We can think about it as about "color", so there's primary regular color and secondary with underscores to mark side-effects.
So, for me it seems in that way it's easier to concentrate on how functions are composed.
What community thinks about that? Can we turn it into convention, pattern or a good practice? Perhaps it would be possible to detect such side-effect procedures and rename them accordingly on a next edition change? Or should I just stop inventing and must rename functions as they were originally?