Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smaller Methods

Following the guidelines given in "Clean Code" by Uncle Bob Martin, I'm trying to make my methods smaller.

One recommendation he gives is that methods that contain a trys should invoke other methods that don't involve the exceptional cases.

My problem is one of naming.

Usually by the time my method only contains the try expression, there's not much left and the name of the method perfectly describes what it does except for the exception.

What conventions do you use for naming the "non-exceptional" method that the exceptional one will call?

As an example, this is a method I'm looking at:

private void generateAndAttachDocumentFromTemplate(File templateFile) {
  try {
    File generatedDocument = generateDocumentFromTemplate(templateFile);
    if (generatedDocument != null) {
      attachDocument(generatedDocument, container);

      attachmentsPanel.reload();

      SystemControl.openDocument(generatedDocument);
    }
  } catch (Exception ex) {
    Notifier.notifyIT(App.user().getEmail(), ex);
    Dialogs.complain("Can\'t Generate Document");
  }
}
like image 772
Allain Lalonde Avatar asked Dec 22 '22 06:12

Allain Lalonde


1 Answers

I use the convention (which I think he suggests in the book) where you have methodName and tryMethodName.

like image 76
willcodejavaforfood Avatar answered Jan 17 '23 19:01

willcodejavaforfood