Code Complete表示,始终使用块标识符是一种很好的做法,既是为了清晰起见,也是作为一种防御措施。
自从读了那本书后,我就一直虔诚地这样做。有时它似乎过分,如下面的例子。
Steve McConnell 坚持始终使用区块标识符是否正确?您会使用其中的哪一个?
//naughty and brief
with myGrid do
for currRow := FixedRows to RowCount - 1 do
if RowChanged(currRow) then
if not(RecordExists(currRow)) then
InsertNewRecord(currRow)
else
UpdateExistingRecord(currRow);
//well behaved and verbose
with myGrid do begin
for currRow := FixedRows to RowCount - 1 do begin
if RowChanged(currRow) then begin
if not(RecordExists(currRow)) then begin
InsertNewRecord(currRow);
end //if it didn't exist, so insert it
else begin
UpdateExistingRecord(currRow);
end; //else it existed, so update it
end; //if any change
end; //for each row in the grid
end; //with myGrid