Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!psuvax1!psuvm!odx From: ODX@PSUVM.BITNET (Tim Larson) Newsgroups: comp.lang.modula2 Subject: Re: The WITH statement Message-ID: <89324.084100ODX@PSUVM.BITNET> Date: 20 Nov 89 13:41:00 GMT References: <89321.154018ODX@PSUVM.BITNET> <2353@gmu90x.gmu.edu> Organization: Penn State University Lines: 25 In article <2353@gmu90x.gmu.edu>, jbaker@gmu90x.gmu.edu (jbaker) says: > >I always thought of a WITH statement differently. It computes the location >of the record just once, freezes it, and uses that record throughout the >WITH statement. Thus, not only does it reduce source code size, it also >increases program efficiency. > This is a good point, it *should* increase efficiency, but it also may not! A good compiler optimizes code for the programmer, but WITH broke the optimizer in mine (JPI) and I don't believe it's the compiler's fault. To maintain correctness, it had to do the computation for the WITH statement, then use that computation to reference the record. When I wrote the same code and removed the WITH, the code size and execution time was reduced! The reason is that the compiler was then freed to optimize the record ref. to registers and reduce the code size. (Of course, this type of optimization is specific to PCs.) The upshot is, the optimization forced on the programmer by remembering the subtleties of the WITH statement is overshadowed by the potential of a good optimizing compiler, and the potential cost is correctness! It's interesting to note that JPI's manual, when mentioning WITH, mildly discourages its use. -Tim Larson odx@psuvm.bitnet