优化版面

2019-01-14

优化版面


关于代码编写风格的最后一条建议是:尽量使用空白优化版面。这一条很容易做到,只需要在写复合句时,以上一句为参照,下一句向右缩进两个空格,复合句内嵌的复合句缩进四个空格,依此类推。例如:

if ... then
 statement;
if ... then
begin
 statement1;
 statement2;
end;
if ... then
begin
 if ... then
   statement1;
 statement2;
end;

相似的缩进格式常用于变量或数据类型声名区,也可用于语句的续行:

type
 Letters = set of Char;
var
 Name: string;
begin

{ long comment and long statement, going on in the
    following line and indented two spaces }
  MessageDlg ('This is a message',
    mtInformation, [mbOk], 0);

提出以上代码编写格式只是向你建个议而已,这样代码能更加易读,其实代码格式并不影响编译结果。在本书的例子和代码段中我始终坚持使用上述代码风格,Delphi 中的源代码、手册和帮助例子均采用了相似的格式化风格。


阅读167