factory_boy icon indicating copy to clipboard operation
factory_boy copied to clipboard

Improve strategy names

Open jams2 opened this issue 2 years ago • 1 comments

The problem

The strategy names build and create are not distinct enough in meaning from each other. This means it's hard to remember which does what. In an informal slack poll at my workplace, ~10% of developers agreed with me that they needed to look up the documentation frequently to be sure they were correct. I have worked extensively on the project https://github.com/wagtail/wagtail-factories, so consider myself reasonably familiar with factory_boy, but struggle to remember which strategy is which!

Proposed solution

I would love to see aliases to the .build and .create methods in factory_boy that more explicitly communicate what they do. Off the top of my head, .in_memory and .persist seem like reasonable options, but I'm open to bikeshedding.

I am happy to contribute a PR to this effect if this is agreeable.

jams2 avatar Nov 22 '23 16:11 jams2

I don't think creating aliases would be the way to go; in my experience, it doesn't add any benefit and confuse people even more. Users discovering the library will want to know the different between build and in_memory (or create and persist) just to discover they mean the same thing.

However, I think the docstrings could be improved. If you are using an IDE with a LSP integration, you'll be able to know which method is doing what: image

Viicos avatar Jan 17 '24 07:01 Viicos