any interest in renaming some functions to have better names?

Robert P. J. Day rpjday at mindspring.com
Sun Mar 26 14:32:16 UTC 2006


  as one example, in libbb/ask_confirmation.c:

	int bb_ask_confirmation(void)
	{
	... return 1 if "yes", 0 if "no".
	}

this is the sort of thing that is unnecessarily obscure since it's not
clear what it means to ask for confirmation just based on the function
name alone.

  one of my favourite SW design books gives the following analogy.  if
you want to write a function that validates a SSN, *don't* call it
"validate_SSN" so that you end up invoking it with:

  if (validate_SSN(number)) { ...

a programmer looking at that won't be sure what that function is
supposed to do or what it returns.  a much better function name would
reflect the actual question being asked:

  if (is_a_valid_SSN(number)) { ...

given the original vague function call above, you end up with things
like:

  if (!bb_ask_confirmation()) {
  if (bb_ask_confirmation() == 0)

a better choice would be, perhaps, one of:

  if (bb_confirm_request())
  if (bb_confirm_action())
  if (bb_confirm())

*now* it's clear what you expect to get back.  thoughts?

rday



More information about the busybox mailing list