I do believe that the more the method is expressive, the more readable, and consequently, maintainable the code will be. Consider the following two cases:
Case 1:
void showCustomerData(customerId){
Customer customer = getCustomer(CustomerId);
customerPanel.setVisible(customer.isCustomerEnabled());
}
Case 2:
void showCustomerData(customerId){
Customer customer = getCustomer(CustomerId);
//always show customer panel
customerPanel.setVisible(true);
}
In the first case, it is clear what the function "setVisible" is doing, but if you want to read it, you would say:
set the customer panel to visible if the customer is enabled or set it
to hidden if the customer is disabled.
While its more descriptive to say:
- check the status of the customer:
- if the customer is enabled then show the customer's panel
- otherwise, hide it
which will change the "Case 1" function into the following:
void showCustomerData(customerId){
Customer customer = getCustomer(CustomerId);
if(customer.isCustomerEnabled()){
customerPanel.Show();
}
else{
customerPanel.Hide();
}
}
it produces more code, but is more readable.
The second case has an obvious flaw, which is, you already know that you want to show the panel, so why not use the "Show" function ?
I am not saying that using "setVisible" is absolutely wrong, but it gets confusing when you try to read code not written by you over time, and it does not conform with the "A function should perform only one operation" rule.