看上去简洁的代码,更有助于理解。我喜欢下面风格的代码:
field := rc.GetFields()
zjj = ""; fjj = "" ; trayCode = ""
if field[0].GetValue() != nil { zjj = field[0].GetValue().(string) }
if field[1].GetValue() != nil { fjj = field[1].GetValue().(string) }
if field[2].GetValue() != nil { trayCode = field[2].GetValue().(string) }
但非常不幸,它会被gofmt无情的格式化成如下格式:
field := rc.GetFields()
zjj = ""
fjj = ""
trayCode = ""
if field[0].GetValue() != nil {
zjj = field[0].GetValue().(string)
}
if field[1].GetValue() != nil {
fjj = field[1].GetValue().(string)
}
if field[2].GetValue() != nil {
trayCode = field[2].GetValue().(string)
}
满眼的羁绊啊。好吧,我发现了这样写,可以让代码看上去简洁一点:
if zjj = ""; field[0].GetValue() != nil {
zjj = field[0].GetValue().(string)
}
if fjj = ""; field[1].GetValue() != nil {
fjj = field[1].GetValue().(string)
}
if trayCode = ""; field[2].GetValue() != nil {
trayCode = field[2].GetValue().(string)
}
over,happy a nice day