【发布时间】:2016-10-27 21:57:04
【问题描述】:
我正在编写一些代码,但我不确定哪个更好。一方面,它更容易阅读正在发生的事情,但我有更多的代码行。 另一方面,你的代码行更少,但我认为更难理解。
String imp = importance.getSelectedItem().toString();
String title_str = title.getText().toString();
String body_str = body.getText().toString();
String location_str = location.getText().toString();
int day = date.getDayOfMonth();
int month = date.getMonth()+1;
int year = date.getYear();
int hh = time.getCurrentHour();
int mm = time.getCurrentMinute();
String date_str = year+"/"+month+"/"+day+" " + hh+":"+mm +":00"; // yyyy/MM/dd HH:mm:ss
long dateMilliseconds = new Timeconversion().timeConversion(date_str);
Conference conference = ConferenceBuilder.conference()
.id(idConf)
.importance(Double.parseDouble(imp))
.title(title_str)
.body(body_str)
.location(location_str)
.timeInMilliseconds(dateMilliseconds)
.build();
或
Conference conference2 = ConferenceBuilder.conference()
.id(idConf)
.importance(Double.parseDouble(importance.getSelectedItem().toString()))
.title(title.getText().toString())
.body(body.getText().toString())
.location(location.getText().toString())
// yyyy/MM/dd HH:mm:ss
.timeInMilliseconds(new Timeconversion().timeConversion(date.getYear()+"/"+date.getMonth()+1+"/"+date.getDayOfMonth()+" " + time.getCurrentHour()+":"+time.getCurrentMinute() +":00"))
.build();
【问题讨论】:
-
追求可读性。顺便说一句,这个词是“一块”,而不是“和平”。 “和平”意味着不打架。
-
谢谢@MikeDunlavey
-
另外我认为这最好作为一个java问题。我认为这里没有与 Android 相关的内容或需要了解 Android 的内容。
-
虽然是安卓代码我觉得你说的对,我还是删掉吧。谢谢
标签: java performance optimization