舊專案必學技術整理 - Java coding style & 前後端 DEBUG

Posted by Tim Lin on 2018-12-03

Java coding style 注意事項

1
2
3
private String fyr = StringUtils.EMPTY;
// v.s. //
private String fyr = ""; // better
1
2
3
4
5
if (!StringUtils.equals("G3", toPos)) {...}
// v.s. //
if (!Objects.equals("G3", toPos)) {...}
// v.s. //
if ("G3".equals(toPos)) {...} // better
1
2
3
4
5
6
7
8
9
List<Cta612pDto> cta612Dtos = sqlExecutor
.queryForList(query, Cta612pDto.class);
if (CollectionUtils.isNotEmpty(cta612Dtos)) {...}

// v.s. //

List<Cta612pDto> cta612Dtos = sqlExecutor
.queryForList(query, Cta612pDto.class);
if (!cta612Dtos.isEmpty()) {...} // better
1
2
3
private BigDecimal pAmt = new BigDecimal(0);
// v.s. //
private BigDecimal pAmt = BigDecimal.ZERO; // better
1
2
3
4
5
6
if (Arrays.asList(new String[] {"20", "21"})
.contains(pAge)) {...}
// v.s. //
private static final Set<String> VALID_P_AGES =
ImmutableSet.of("20", "21");
if (VALID_P_AGES.contains(pAge)) {...} // better

請做 local variable …

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

page = list.get(i).getAge();
pacc = list.get(i).getAcc();
pasp = list.get(i).getAsp();
pagency = list.get(i).getAgency();
if (StringUtils.isNotBlank(list.get(i).getName())
&& StringUtils.equals("Z0", list.get(i).getAsp())) {
pname = "追加減預算";
} else {
pname = list.get(i).getName();
}
paccalt = list.get(i).getAccalt();
pypay = list.get(i).getYpay();
pctl = list.get(i).getCtl();
pdispos = list.get(i).getDispos();


6. 如何 debug (chrome & eclipse debug)

chrome:

https://developers.google.com/web/tools/chrome-devtools/javascript/step-code?hl=zh-tw

https://pjchender.blogspot.com/2017/06/chrome-dev-tools.html

https://raygun.com/blog/debug-javascript-google-chrome/

https://leeon.gitbooks.io/devtools/content/

https://medium.freecodecamp.org/how-you-can-improve-your-workflow-using-the-javascript-console-bdd7823a9472

eclipse:

https://cpmaltose.wordpress.com/2017/08/06/debugger-fast-tutorial/

http://www.vogella.com/tutorials/EclipseDebugging/article.html