Functions are the muscles of a program, they perform changes. Here are some tips to write efficient and maintainable functions:

1. Small. Smaller the functions easier it is to debug errors. Also, smaller functions are reusable.

2. Do One Thing Every function must have a clear purpose and it should perform only that.

"FUNCTIONS SHOULD DO ONE THING. THEY SHOULD DO IT WELL . THEY SHOULD DO IT ONLY."- Uncle Bob

3. Use Descriptive Names Function names should be verbs.Use meaningful, easy to understand names for functions.A long descriptive name is better than a long descriptive comment. These will also help to clearly understand the design of the module.

4. Take minimum number of arguments. Less number of arguments helps to improve readibility and understanding along with simplfying the testing process. According to Uncle Bob, three should be the maximum number of arguments any function takes.

5. Keep your functions SideEffect-free. A function should only perform one thing, described by its name. Anything else done by the function is a side effect and should be avoided. Eg: In the following example, the checkPassword function should only check the password but it also initializes the session. This is not described in the function name, so anyone who calls checkPassword stands to reinitialize the session as a side effect.

public class UserValidator  {   
    private Cryptographer cryptographer;   
 public boolean checkPassword(String userName, String
password) { 
    User user = UserGateway.findByName(userName);   
 if (user !=
User.NULL) { String codedPhrase = user.getPhraseEncodedByPassword();   
String phrase = cryptographer.decrypt(codedPhrase, password);  

 if
(\"Valid Password\".equals(phrase)) { Session.initialize();  

 return true;  
  

} } return false;  
  
 } }