delphi – 我应该在我的代码中使用块标识符(“end;”)吗?
发布时间:2020-12-15 04:22:01 所属栏目:大数据 来源:网络整理
导读:Code Complete表示总是使用块标识符是一种好的做法,无论是为了清晰还是作为防御措施. 自读这本书以来,我一直在虔诚地做这件事.有时看起来似乎过多,如下面的情况. Steve McConnell是否有权坚持始终使用块标识符?您会使用以下哪些? //naughty and briefwith
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 解决方法
就个人而言,我更喜欢第一个,因为恕我直言“结束”;不要告诉我太多,一旦一切都接近,我可以通过身份来判断什么时候会发生什么.
我相信在使用大型语句时,块更有用.您可以进行混合方法,在其中插入一些“开始…结束;”并注释它们结束的内容(例如将其用于with和第一个if). 恕我直言,您也可以将其分解为更多方法,例如,该部分 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 可以采用单独的方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |