views:

35

answers:

4

This question might seem stupid but i nonetheless i believe it's a worth asking questioin.

I work on some web application when we use tags which are attached to articles. When adding new article users provides a list of tags he wish to associate with his new article.

So when the form is submitted and my MVC controller processes request i have a string with tags from the form. I split the tags string and i get an array of tag words. Then i need a list o tags ids from db. So i came up with a method that takes a list of tag words and checks if each tag already exists in db. If given tag is already in db then tag's id is appended to result array. If tag does not exist in db it is created and then id of just created tag is appended to result array.

My question is: what is the best name for such a method? This method creates tags only if necessary and returns list of tags' ids.

I tried this names, but none of them looks right to me:

  • fetchTagsIds(List tagWordsList)
  • createOrFindsTagsIds(List tagWordsList)
  • obtainTagsIds(List tagWordsList)

I need a name that really reflects what the method does. Thanks for your help :)

+3  A: 

I'd drop the "s" in "Tags". So that the method is:

FetchTagIds(List tagWordsList)

Chris Lively
A: 

IdsOfTags. That it creates them is an implementation detail (as is the fact that it uses a relational database in the first place). All that matters is that it gives you unique ids for tags (e.g. it could also hash them with a perfect hash function, or lookup an ID in the web.

Martin v. Löwis
A: 

If you're having trouble coming up with a name that accurately describes what your method does, that could be because you method does too much. Perhaps it would be better to refactor it into two:

  1. findTagsByName(List tagNames) would return a list of Tag objects based on list of names you pass in
  2. persistTags(List tags) - or saveTags(), or createTags() - would persist a list of Tag objects.
ChssPly76
A: 

getTagIDs?

Get suggests that the code will do something to get an ID when one doesn't exist to fetch.