源代码是一组语句。我们必须使用分隔符来分隔语句。如果我们使用换行符作为分隔符,我们就无法构建我们的代码。很长的行只能通过滚动阅读。 (为了避免滚动,长行通常会被分割。)例如:
ParserUtils.RefreshProperty(m_cfg.PORTAL_ID, ParserUtils.CreateHashFromUrl(strDetailLinkUrl), Convert.ToInt32(m_cfg.Type), strPrice, strAddress, strStreet, strPostCode, strFeatures, strDescription, strImgFile, strBedrooms, strReception, strBath, strStatus, strLink, strPropType, strOutside, strTenure, strKeywords, strFullText, strContactInfo, m_ieBrowser.URL);
非常难看,我们将这一行分成几行以使其更具可读性:
ParserUtils.RefreshProperty(m_cfg.PORTAL_ID,
ParserUtils.CreateHashFromUrl(strDetailLinkUrl),
Convert.ToInt32(m_cfg.Type), strPrice,
strAddress, strStreet, strPostCode, strFeatures, strDescription, strImgFile,
strBedrooms, strReception, strBath, strStatus, strLink, strPropType,
strOutside, strTenure, strKeywords, strFullText, strContactInfo,
m_ieBrowser.URL);
如果换行符是分隔符,这将是不可能的。如果换行符是运算符,Ifs、whiles 和 fors 将一团糟。考虑这段代码:
for (int i = 0; i < n; i++)
{
if (i % 2 == 0)
{
System.out.println("It can be divided by two");
}
{
System.out.println("It can't be divided by two");
}
}
如果换行符是运算符而不是分号,那么这个源代码会很丑:
for (int i = 0
i < 0
i++) { if (i % 2 == 0) { System.out.println("It can be divided by two")
} { System.out.println("It can't be divided by two")
} }
此代码难以阅读,并且作为分隔符在逻辑上是有效的。例如,我的妻子将我的任务写在纸上(一种算法),如下所示:
Buy food(Bread, Meat, Butter),
Go and pay the taxes,
Call your mother, because she wants to talk to you
这些任务用逗号分隔,但请注意参数也用逗号分隔。我们必须区分逗号作为参数分隔符和逗号作为任务的分隔符,因为计算机不如人类聪明。总而言之,任务分隔符是一个比参数分隔符更大的逗号。所以语句的分隔符是分号,参数的分隔符是逗号。