From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d694b5818a5102b1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-09-22 15:16:22 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!europa.eng.gtefsd.com!newsxfer.itd.umich.edu!zip.eecs.umich.edu!panix!cmcl2!thecourier.cims.nyu.edu!thecourier.cims.nyu.edu!nobody From: dewar@cs.nyu.edu (Robert Dewar) Newsgroups: comp.lang.ada Subject: Re: Naive question about system dependencies Date: 22 Sep 1994 10:15:14 -0400 Organization: Courant Institute of Mathematical Sciences Message-ID: <35s3hi$67p@gnat.cs.nyu.edu> References: <35f559$mad@info.epfl.ch> <85B716C4188@annwfn.com> NNTP-Posting-Host: gnat.cs.nyu.edu Date: 1994-09-22T10:15:14-04:00 List-Id: The whole idea in using separate bodies should be to completely avoid code duplication. Only the code that is system dependent, and hence NOT duplicated, i.e. the code that would go inside the range of an ifdef, should be in separate bodies, code outside the ifdef can be shared. This isn't possible to achieve completely in all cases, but you can come very close by building appropriate abstractions, and if you have a decent compiler which does inlining properly, there should be no efficienc y loss from this kind of abstraction. To emphasize, this is a design princinple which cannot always be met, but far too much code is duplicated in situations where there has not been nearly enough effort in attempting to meet this requirement. Note that the disastrous thing about ifdefs is that it gets very hard to even make sure that the module is free of syntax errors for all cases. Suppose we have 20 ifdefs in one module, each with two settings. THen it takes 1,000,000 compilations just to make sure that all possibilities compile (and 1,000,000 careful test runs to make sure they all work). If on the other hand, you have one common module, and two versions each of 20 little modules, then you have to compile only 41 files to check syntax correctness, and you can at least do 41 separate unit tests (the full integration testing would of course take 1,000,000 runs, there's no way around that, but at least it's better to have unit testing than nothing at all). Best of all is to try to avoid special casing in the first place. That's cerainly the approach we try to use in GCC, where we have several hundred possible configurations, and we are VERY unfriendly to target dependent code, though we can't completely avoid it. In my experience, the ability to use ifdef's is a disaster for big systems. All to often, you get ifdefs all over the place, and the sources become completely unmanagable.