还没工作,自己学习过程中写的项目里方法名长这样,对吗?

2020-02-21 17:29:28 +08:00
 Newyorkcity
public void insertAuthenticationCodeIntoRedis

public String getAuthenticationCodeForWebRegistration

public boolean examWhetherAuthenticationCodeInRegistrationCoincident

public boolean examWhetherShouldBeInStage3

public void deleteAuthenticationCodeForRegistration

因为我发觉我越写越长而且强迫症(就是把事情说明白)越来越严重了,我怀疑再这样下去我就能在方法名里写出一个可以用来做六级翻译题的句子了。。。

谢谢指点

869 次点击
所在节点    问与答
6 条回复
vanillaxxx
2020-02-21 17:38:30 +08:00
1.insertAuthCode
2.getAuthCode
3.checkAuthCode
4.checkAuthStatus
5.deleteAuthCode
lxk11153
2020-02-21 17:40:46 +08:00
233 spring data jpa 就是这样的
from: List<User> findByEmailAddressAndLastname(String emailAddress, String lastname);
to__: select u from User u where u.emailAddress = ?1 and u.lastname = ?2
see_: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation
cmdOptionKana
2020-02-21 17:46:26 +08:00
预估一下同一个 Class 内这个 Authentication Code 有没有必要插入别的地方,如果没有就先用 insertAuthCode。

这个部分“IntoRedis”是需要和别的函数区分开来才有意义的。
FragmentLs
2020-02-21 17:48:59 +08:00
没必要吧...除非你把全部逻辑全都丢在一个 Class 里,不然直接 toRedis, getAuth, 一般没人用 exam 或 whether,直接 check,is,isNot

不过测试里这样写个人觉得不错
cmdOptionKana
2020-02-21 17:50:45 +08:00
另外,看看你用的编辑器(通常是 IDEA )对代码的注释是怎样提示的,在使用这个方法的地方查看方法信息,如果能显示注释,那么方法名本身就没有必要太详细。
aguesuka
2020-02-22 08:42:36 +08:00
把相同的单词抽离,放在一个 class 里,intoRedis 改成 cache。判断一个对象和其他对象的关系时,不要用数据模型,而是用业务模型。比如'检查用户是否注册'改为'用户(class)'#'is 注册(method)'

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/646417

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX