Bob worked at a small company. There’s a messy history in its founding. The owner, Aaron, worked for another company making basically the same software, until he finally got fed up with their coding style and practices. So he quit to found his own company, with his own rules about things, like how many blank lines there should be before a for
loop (exactly 1), how to order variable declarations (alphabetically, with “::” coming after “z”), and how source control should be organized (about as organized as organized crime).
Aaron didn’t waste a lot of time managing, and made sure to keep his hands in the code. Of course, no one wanted to touch the code after he did, which meant Aaron wasn’t just the owner, but he was a one-man team. The other teams might deliver features, but Aaron’s team delivered vision. Well, vision, and code blocks like this, which parse parameters off the command-line:
typedef enum context_option_type_e
{
context_option_type_unknown = 0,
context_option_type_bool = 1,
context_option_type_double = 2,
context_option_type_float = 3,
context_option_type_string = 4,
context_option_type_uint32 = 5,
context_option_type_uint64 = 6,
context_option_type_max,
} context_option_type_e;
bool
get_bool_context_option(
const uint32_t context_option) const
{
bool return_value = false;
if (context_option > this->vector_context_option_to_type_mapping.size())
{
assert(false && "Invalid context option specified.");
goto exit;
}
if (
this->vector_context_option_to_type_mapping[context_option] ==
context_option_type_bool)
{
::std::string string_context_option_lowercase;
const ::std::string &string_context_option =
this->vector_string_context_options[context_option];
string_context_option_lowercase.resize(
string_context_option.size());
::std::transform(
string_context_option.begin(),
string_context_option.end(),
string_context_option_lowercase.begin(),
::std::tolower);
if (
(string_context_option_lowercase.compare("1") == 0) ||
(string_context_option_lowercase.compare("true") == 0) ||
(string_context_option_lowercase.compare("yes") == 0))
{
return_value = true;
}
}
else
{
assert(false && "Context option is not a bool type.");
}
exit:
return return_value;
}
You’ll notice that the enum defines 6 types of option, and this function is only for the bool
option. You might think, “Aaron copied and pasted this code six times for the different types,” but you’d be wrong. Aaron just didn’t implement them.
Aaron continues to be the most prolific committer, even if no one knows exactly what he's working on. At least his variable names are always perfectly ordered.
For those unfamiliar with C, I recommend investigating getopt
, the POSIX standard function for parsing command-line options.