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
– Fabio Oct 25 '20 at 18:12_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) – xenia Oct 25 '20 at 23:28list_push()
and the version of the method that comes with caveat as_list_push()
. The understanding is that in Python names starting with underscore are usually considered private by convention. In languages that have actual access specifier, you can use private or protected specifier to mark the unsafe methods. – Lie Ryan Oct 30 '20 at 10:11