Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

method name for a long method

The good style (Clean Code book) says that a method's name should describe what the method does. So for example if I have a method that verifies an address, stores it in a database, and sends an email, should the name be something such as verifyAddressAndStoreToDatabaseAndSendEmail(address);

or

verifyAddress_StoreToDatabase_SendEmail(address);

although I can divide that functionality in 3 methods, I'll still need a method to call these 3 methods. So a large method name is inevitable.

Having And named methods certainly describes what the method does, but IMO it's not very readable as names can be very very large. How would you solve it?

EDIT: Maybe I could use fluent style to decompose the method name such as:

verifyAddress(address).storeToDatabase().sendEmail();

but I need a way to ensure the order of invocation. Maybe by using the state pattern, but this causes the code to grow.

like image 563
ejaenv Avatar asked Dec 28 '22 14:12

ejaenv


1 Answers

How I approach this is to make the 3 smaller methods as you mentioned and then in the higher method that calls the 3 smaller ones, I name it after the "why" I need to do those three things.

Try to define why you need to do those steps and use that as the basis of the method name.

like image 86
JamesEggers Avatar answered Feb 07 '23 17:02

JamesEggers