问题描述
警告::这是我发布的不是很严肃的问题/讨论,但是我敢打赌大多数开发人员都在考虑这个问题" ...
Warning: This is a not very serious question/discussion that I am posting... but I am willing to bet that most developers have pondered this "issue"...
对于要从某个地方获取数据并返回数据的方法的命名约定,总是希望获得其他意见.
Always wanted to get other opinions regarding naming conventions for methods that went and got data from somewhere and returned it...
大多数方法名称有些简单明了... SaveEmployee(),DeleteOrder(),UploadDocument().当然,对于类,您极有可能分别使用简短形式... Save(),Delete(),Upload().
Most method names are somewhat simple and obvious... SaveEmployee(), DeleteOrder(), UploadDocument(). Of course with classes you would most likely use the short form...Save(), Delete(), Upload() respectively.
但是,我一直在努力采取初步措施……如何获取数据.似乎对于每个项目,我最终都会在不同的命名约定之间跳来跳去,因为我对上一个使用的项目从来都不满意.据我所知,这是可能性->
However, I have always struggled with initial action...how to get the data. It seems that for every project I end up jumping between different naming conventions because I am never quite happy with the last one I used. As far as I can tell these are the possibilities -->
- GetBooks()
- FetchBooks()
- RetrieveBooks()
- FindBooks()
- LoadBooks()
您的想法是什么?
推荐答案
这一切都是关于一致的语义 a>;
It is all about consistent semantics;
-
getBooks()
是当您获得所有与对象,则表示该集合的条件是已经定义好了,它们的来源是一个隐藏的细节. -
findBooks(criteria)
是什么时候试图找到一个子集基于参数的书方法调用,通常充满了不同的搜索条件 -
loadBooks(source)
是您从外部来源加载,像文件或数据库. - 我不会使用之所以提取/检索,是因为它们太含糊并与 get 混淆,并且没有与术语相关的明确语义.
getBooks()
is when you are gettingall the books associated with anobject, it implies the criteria for the set isalready defined and where they are coming from is a hidden detail.findBooks(criteria)
is when are trying to find a sub-setof the books based on parameters tothe method call, this will usuallybe overloaded with different searchcriterialoadBooks(source)
is when you areloading from an external source,like a file or db.- I would not usefetch/retrieve because they are too vague and get conflated with get and there is no unambiguous semantic associated with the terms.
示例: 获取 表示某些实体需要去获取遥远的东西并将其带回.狗拿棍子, 检索 是同义词为 fetch 提供附加的语义,即您可能之前也拥有该东西. get 是,这意味着您仅拥有某物,没有人其他人可以同时获取它.
Example: fetch implies that some entity needs to go and get something that is remote and bring it back. Dogs fetch a stick, and retrieve is a synonym for fetch with the added semantic that you may have had possession of the thing prior as well. get is a synonym for obtain as well which implies that you have sole possession of something and no one else can acquire it simultaneously.
与意义有关的语言学和逻辑学分支
含糊不清或含糊不清含义的单词因其基于个人见解的偏见和偏见而被不同的人赋予不同的语义,并且永远都不会结束.
words with vague or ambigious meanings are given different semantics by different people because of their predjudices and preconceptions based on their personal opinions and that will never end well.
这篇关于获取数据的方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!