Code Complete dice que es una buena práctica usar siempre usar identificadores de bloque, tanto por claridad como como medida defensiva.¿Debo usar identificadores de bloque ("end;") en mi código?
Desde que leí ese libro, he estado haciendo eso religiosamente. A veces parece excesivo, como en el caso a continuación.
¿Steve McConnell tiene razón al insistir en usar siempre identificadores de bloque? ¿Cuál de estos usarías?
//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
Code Complete también podría recomendar un título más preciso para esta pregunta. – Smandoli
Se arregló el título para el OP. –
Mi * Dios *, ¿qué idioma es eso? –