I have a method for pulling data from a database, and I want it to get this:
Limit of Five entries, Item type is Newsletter, Needs to be active (PublishDate < DateTime.Now)
So I'm thinking of naming it GetFiveActiveNewslettersByCreatedDate()
This seems a little long to me. I looked on the site for a good way to name things like this, how would you handle it?
When two chains of equal size are present. The chain with more number of side chains forms a part of the longest carbon chain while the other one is considered the complex substituent. On the complex substituent, numbering is done from the end attached to the principal chain.
How about something like this instead?
public IEnumerable<Newsletter> GetActiveNewsletters(int maxRecords = 5)
{
// ...
}
Top 5 is still the default, but it's not overly specific anymore.
The reason I would avoid baking "five" into the name, personally, is what it might mean down the line.
For example, what if later, there were some demand for 10 newsletters in certain scenarios instead of 5? Well, you'd create an additional method GetTenActiveNewslettersByCreatedDate()
. And now, you have a 'design pattern' that subsequent developers will follow when 20, 50, 100 newsletters are needed. This is a design that will rot, and you can stave it off now by parameterizing the five.
Of course, this might be YAGNI/speculative generality. If 5 really is some kind of magic, hard-fast, will never change rule, then you might cautiously bake it in. I just find that I've regretted doing and seeing things like that far, far more often than not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With