Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(string append): can concatenate strings using string placeholders #66

Closed
zhanyeye opened this issue Nov 24, 2021 · 3 comments
Closed
Assignees
Labels
refactor refactor code

Comments

@zhanyeye
Copy link
Member

private String voteResultInfo(String title, boolean result, int acceptCnt, int totalCnt) {
return new StringBuilder().append(" #### 投票结果 \n ##### 论文: ").append(title)
.append(" \n 最终结果: ").append(result ? "Accept" : "reject")
.append(" \n Accept: ").append(acceptCnt).append(" 票 \n ")
.append("Reject: ").append(totalCnt - acceptCnt).append(" 票 \n ")
.append("已参与人数: ").append(totalCnt).append("人 \n ").toString();
}

是否需要用 String.format 代替 append(), 性能和可读性的权衡?
https://cowtowncoder.medium.com/measuring-performance-of-java-string-format-or-lack-thereof-2e1c6a13362c

@zhanyeye zhanyeye self-assigned this Nov 24, 2021
@zhanyeye zhanyeye added the refactor refactor code label Nov 24, 2021
@lilingj
Copy link
Member

lilingj commented Nov 24, 2021

可以把消息主体提取出来,做成消息模板,与某个类绑定,生成消息。(我记得golang里标准库有html/template这个库,就是干这个事的

@zhanyeye
Copy link
Member Author

zhanyeye commented Nov 24, 2021

好主意,有时间可以介绍一下,我也学习一下~

@lilingj
Copy link
Member

lilingj commented Nov 24, 2021

相当于前后端不分离时用后端做渲染,我新开个issue,有时间就重构这一部分

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor refactor code
Projects
None yet
Development

No branches or pull requests

2 participants