I\'m sure many of us have seen method names like this at one point or another: U
ID: 639315 • Letter: I
Question
I'm sure many of us have seen method names like this at one point or another:
UploadTheFileToTheServerPlease
CreateATemporaryFile
WriteTheRecordToTheDatabase
ResetTheSystemClock
That is, method names that are also grammatically-correct English sentences, and include extra words purely to make them read like prose. Personally, I'm not a huge fan of such "literal" method names, and prefer to be succint, while still being as clear as possible. To me, words like "a", "an", and "the" just look plain awkward in method names, and it makes method names needlessly long without really adding anything useful. I would prefer the following method names for the previous examples:
UploadFileToServer
CreateTemporaryFile
WriteOutRecord
ResetSystemClock
In my experience, this is far more common than the other approach of writing out the lengthier names, but I have seen both styles and was curious to see what other people's thoughts were on these two approaches.
So, are you in the "method names that read like prose" camp or the "method names that say what I mean but read out loud like a bad foreign-language-to-English translation" camp?
Explanation / Answer
I'll agree that prose methods suck with one exception:
Unit Test Cases
These are generally never called in your code and show up in test reports. As such, it's handy to have readouts with a bit more prose:
AddingACustomerOrderFailWhenCustomersIdIsInvalid : Failed
OutOfBoundsPriceReturnsAnError : Passed
CanDeleteAnEventFromASeason : Passed
Even this should be done sparingly, but I can see it as at least one case where grammatical additions can make it a little easier to express what passed and what failed. This is, of course, unless your language/framework provides a good mechanism for test-descriptions in the test readout other than method names, in which case ignore this one too.