看到一句话,心有戚戚
语法层面的(nontrivial的)错误往往预示着语意层面的错误。例如,循环依赖导致的语法错误往往暗示抽象设计存在问题。
-- 转至 http://fanfou.com/statuses/uiT9IzmuonQ
我一直想好好写写循环依赖的问题,但不知如何下笔。只是在前段时间的 Blog 末尾提了一下。 (见 良好的模块设计 的最后两段。)
这些是我最近用 C 写了很多代码后悟到的。
C 往往允许程序员省略函数原型声明,只需要你把被依赖的函数实现列在前面即可。
刚学写 C 程序的时候,我老喜欢把各种函数的声明列在一起放在一个头文件中。后来明白了应该尽可能隐藏实现细节这个道理,转而把内部函数的声明放在独立的内部使用的头文件中。
今天,我发现,如果能保证没有循环依赖,所有非接口的函数都不必另外写一个声明;这一点可以反过来促成更好的设计。
在用 C++ 的日子里,我对这些一直没能有太清晰的认识。想来是因为 C++ 提倡每个类都预先写好类声明有关。
当然,间接递归并不等同于循环依赖。递归正是利用将实现和接口分离的方法,从而消除循环依赖。但解决掉眼前的问题就够了吗?我有点理解为什么当年 Fortran 不支持递归了。
当人们手中的工具越有威力,就越不把跟前的问题看在眼里。能力越大,越难 KISS 。
Comments
Posted by: 七心葵 | (68) May 9, 2011 12:28 PM
Posted by: 七心葵 | (67) May 9, 2011 12:26 PM
Posted by: 七心葵 | (66) May 9, 2011 12:23 PM
Posted by: alioxp | (65) January 8, 2008 08:18 AM
Posted by: alioxp | (64) January 8, 2008 08:01 AM
Posted by: longtrue | (63) June 15, 2007 11:42 AM
Posted by: Cloud | (62) June 14, 2007 02:31 PM
Posted by: liaoliao | (61) June 14, 2007 12:51 PM
Posted by: d | (60) June 14, 2007 12:20 PM
Posted by: rockcarry | (59) June 14, 2007 10:47 AM
Posted by: Atry | (58) June 14, 2007 10:43 AM
Posted by: rockcarry | (57) June 14, 2007 10:34 AM
Posted by: rockcarry | (56) June 14, 2007 10:06 AM
Posted by: Alpha | (55) June 13, 2007 11:29 PM
Posted by: nothanks | (54) June 13, 2007 08:51 PM
Posted by: rockcarry | (53) June 13, 2007 08:24 PM
Posted by: rockcarry | (52) June 13, 2007 08:04 PM
Posted by: liaoliao | (51) June 13, 2007 05:00 PM
Posted by: rockcarry | (50) June 13, 2007 04:46 PM
Posted by: rockcarry | (49) June 13, 2007 04:32 PM
Posted by: rockcarry | (48) June 13, 2007 04:20 PM
Posted by: rockcarry | (47) June 13, 2007 03:58 PM
Posted by: rockcarry | (46) June 13, 2007 03:50 PM
Posted by: Atry | (45) June 13, 2007 03:08 PM
Posted by: dayn9 | (44) June 13, 2007 02:38 PM
Posted by: rockcarry | (43) June 13, 2007 01:14 PM
Posted by: rockcarry | (42) June 13, 2007 10:50 AM
Posted by: rockcarry | (41) June 13, 2007 10:36 AM
Posted by: rockcarry | (40) June 13, 2007 09:53 AM
Posted by: 6spring | (39) June 13, 2007 01:13 AM
Posted by: rockcarry | (38) June 13, 2007 01:13 AM
Posted by: rockcarry | (37) June 13, 2007 12:07 AM
Posted by: nothanks | (36) June 12, 2007 09:10 PM
Posted by: Atry | (35) June 12, 2007 07:57 PM
Posted by: rockcarry | (34) June 12, 2007 06:22 PM
Posted by: rockcarry | (33) June 12, 2007 05:47 PM
Posted by: rockcarry | (32) June 12, 2007 05:42 PM
Posted by: rockcarry | (31) June 12, 2007 05:35 PM
Posted by: rockcarry | (30) June 12, 2007 05:25 PM
Posted by: d | (29) June 12, 2007 03:08 PM
Posted by: Cary | (28) June 12, 2007 11:43 AM
Posted by: Cary | (27) June 12, 2007 11:32 AM
Posted by: rockcarry | (26) June 12, 2007 10:10 AM
Posted by: longtrue | (25) June 12, 2007 09:18 AM
Posted by: rockcarry | (24) June 12, 2007 06:04 AM
Posted by: Cloud | (23) June 11, 2007 09:02 PM
Posted by: david | (22) June 11, 2007 08:32 PM
Posted by: Cary | (21) June 11, 2007 06:48 PM
Posted by: Atry | (20) June 11, 2007 06:27 PM
Posted by: Atry | (19) June 11, 2007 06:20 PM
Posted by: rockcarry | (18) June 11, 2007 06:01 PM
Posted by: rockcarry | (17) June 11, 2007 05:47 PM
Posted by: rockcarry | (16) June 11, 2007 05:31 PM
Posted by: rockcarry | (15) June 11, 2007 05:13 PM
Posted by: Atry | (14) June 11, 2007 04:49 PM
Posted by: Cloud | (13) June 11, 2007 02:24 PM
Posted by: rockcarry | (12) June 11, 2007 01:43 PM
Posted by: rockcarry | (11) June 11, 2007 01:32 PM
Posted by: Cloud | (10) June 11, 2007 01:14 PM
Posted by: rockcarry | (9) June 11, 2007 12:12 PM
Posted by: rockcarry | (8) June 11, 2007 11:41 AM
Posted by: nothanks | (7) June 11, 2007 11:27 AM
Posted by: rockcarry | (6) June 11, 2007 11:10 AM
Posted by: longtrue | (5) June 11, 2007 07:37 AM
Posted by: huangyi | (4) June 10, 2007 01:09 PM
Posted by: zelor | (3) June 10, 2007 11:27 AM
Posted by: Atry | (2) June 10, 2007 09:57 AM
Posted by: Atry | (1) June 10, 2007 09:54 AM