Say that I have two functions that are essentially identical, where one validates its arguments while the other doesn't. The rationale: sometimes you want to be safe and sometimes you want to go fast.
What's your preferred naming convention to distinguish the two? For example:
list_err_t list_push_a(list_t *ref, list_t *item) {
if ((ref != NULL) && (item != NULL)) {
list_push_b(ref, item);
return LIST_ERR_NONE;
} else {
return LIST_ERR_BAD_ARG;
}
}
void list_push_b(list_t *ref, list_t *item) {
item->next = ref->next;
ref->next = item;
}
What would you name list_push_a
and list_push_b
? I think list_push_safe
and list_push_fast
is a bit wordy -- one of them should just be list_push
. (And note that I'm not asking about CamelCase vs snake_case etc...)
addenda...
There have been some great answers already. I should have mentioned up front that the programming environment in question is low-level embedded devices, where speed is important and resources are scant. For example, raising exceptions is not an option...
list_push_if_valid
andlist_push
_unchecked
suffix. These functions are usually also markedunsafe
, but that's a rather Rust-specific feature. Some examples areslice::get_unchecked
(not checking bounds on array access),f64::to_int_unchecked
(not checking for NaN and Infinity) andstr::from_utf8_unchecked
(quite self-explanatory, converts a byte array to a string without checking whether it is valid UTF-8 or not)