获取数据的方法名称 [英] Method names for getting data

查看:93
本文介绍了获取数据的方法名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

警告::这是我发布的不是很严肃的问题/讨论,但是我敢打赌大多数开发人员都在考虑这个问题" ...

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;

在问题标题中,您使用获取数据.这非常 一般而言,您需要定义 getting 的含义 语义上明显无歧义的方式.我提供以下 希望在思考时能使您走上正轨的示例 命名事物.

In your question title you use getting data. This is extremely general in a sense that you need to define what getting means semantically significantly unambiguous way. I offer the follow examples to hopefully put you on the right track when thinking about naming things.

  1. getBooks()是当您获得 所有与 对象,则表示该集合的条件是 已经定义好了,它们的来源是一个隐藏的细节.
  2. findBooks(criteria) 是什么时候试图找到一个子集 基于参数的书 方法调用,通常 充满了不同的搜索 条件
  3. loadBooks(source)是您 从外部来源加载, 像文件或数据库.
  4. 我不会使用 之所以提取/检索,是因为它们太含糊并与 get 混淆,并且没有与术语相关的明确语义.
  1. getBooks() is when you are getting all the books associated with an object, it implies the criteria for the set is already defined and where they are coming from is a hidden detail.
  2. findBooks(criteria) is when are trying to find a sub-set of the books based on parameters to the method call, this will usually be overloaded with different search criteria
  3. loadBooks(source) is when you are loading from an external source, like a file or db.
  4. I would not use fetch/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.

与意义有关的语言学和逻辑学分支

评论证明 get fetch 这样的通用术语具有 没有特定的语义,并且被不同的解释不同 人们.选择一个术语的语义,记录其意图 暗示语义是否不清楚,并与其用法保持一致.

The comments are proof that generic terms like get and fetch have no specific semantic and are interpreted differently by different people. Pick a semantic for a term, document what it is intended to imply if the semantic is not clear and be consistent with its use.

含糊不清或含糊不清含义的单词因其基于个人见解的偏见和偏见而被不同的人赋予不同的语义,并且永远都不会结束.

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.

这篇关于获取数据的方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆