Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have seen the words Fetch and Select used seemingly interchangeably when naming data access layer methods (ex. Person.Select or Person.Fetch). Which one is correct?

My instinct is that the point of the data access layer is to abstract data access and thus the term Fetch would be more of an abstraction perhaps than Select would be. But if one can imagine for a moment that SQL was not an existing technology, the term Select on its own might be appropriate.

share|improve this question

closed as not constructive by pdr, JeffO, Yusubov, Greg Hewgill, Dynamic Jun 5 '13 at 22:51

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

Get and Read are also appropriate. it's a matter of preference. – devnull Jun 5 '13 at 13:01
In some programming languages, fetch implies that multiple rows of data can be returned, while select returns one and only one row of data. – Gilbert Le Blanc Jun 5 '13 at 13:03
Just as a note, in .NET get is a keyword and the code analyzer will often flag a method if its name begins with Get. – Richard Collette Jun 5 '13 at 13:25
@RichardCollette: Not because get is a keyword, but because a method named get in a language that has properties is an anti-pattern. – Robert Harvey Jun 5 '13 at 17:28
I find it interesting that many of the people who have closed this out have answered similar "objective" questions and have earned large reputation numbers as a result. There has not been a lot of debate, and what leads them to believe that a person with specific expertise would not provide a supporting answer? It's not like I asked a question like "Which is better Android or iOS?". I was specific and looking to provide consistency in my design. Relevant I would say. If Martin Fowler chimed in, would the question still be irrelevant? It's turning into a game of Survivor here. – Richard Collette Jun 6 '13 at 3:40
up vote 1 down vote accepted

According to the given comments, I'd also say that it's a matter of preference. When I have to cope with naming issues, I usually look for semantic differences of the words in a dictionary.

fetch - go for and then bring back (someone or something) for someone

select - carefully choose as being the best or most suitable

The word select has a notion of choosing between some elements. This is not the case in a Data Access Layer, because in a specific method you know which entity you want to access and thus, the selecting process rather takes place in the Database Layer itself.

Therefore I'd prefer the word fetch in this case, because, according to the definition, you go for an entity's data and you want to bring it back (=forward it) to the next higher layer, maybe the business logics layer.

share|improve this answer
This did get me thinking. It is the responsibility of the database to select the data (hence the Select statement in SQL) but it is the responsibility of the DAL to fetch the data rather than select the data. Of course this is in the context of database access. If the DAL member is getting data from XML or a file, it may indeed be selecting data but as far as the client of the DAL is concerned the responsibilty is fetching the data. – Richard Collette Jun 5 '13 at 16:03
@RichardCollette You have to evaluate, who is most concerned with the method name you have to choose. This is indeed the client since he'll probably invoke it. – McMannus Jun 5 '13 at 16:35

When to choose between Selectand Fetch I would prefer SELECT because it is used in other technologies (SQL, LINQ, ...) and therefore the "what it will do" is more understandable for developers.

Personally I would choose Query, like used in Hibernate or RavenDb, because it implies that you have to do something else than simply selecting a subset of a collection to get the data.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.