Reputation: 93348
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");
}
}
Upvotes: 4
Views: 774
Reputation:
anytime a method has doThisANDdoThat() is a bad method. methods should do ONE thing and only one thing. Regardless of how "small" they are.
Upvotes: 3
Reputation: 44073
I use the convention (which I think he suggests in the book) where you have methodName and tryMethodName.
Upvotes: 6
Reputation: 597124
Some alternatives:
method
> doMethod
method
> method0
The "non-exceptional" methods should be private
.
Upvotes: 1
Reputation: 1932
You could use the "Impl" convention.
private void generateAndAttachDocumentFromTemplate(File templateFile) {
try {
generateAndAttachDocumentFromTemplateImpl(File templateFile);
} catch (Exception ex) {
Notifier.notifyIT(App.user().getEmail(), ex);
Dialogs.complain("Can\'t Generate Document");
}
Upvotes: 1