Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!lupine!rfg From: rfg@NCD.COM (Ron Guilmette) Newsgroups: comp.lang.c++ Subject: Re: Project experience with C++ Message-ID: <1197@lupine.NCD.COM> Date: 15 Aug 90 23:12:28 GMT References: <397.26c19b74@astro.pc.ab.com> <10329@cadillac.CAD.MCC.COM> Organization: Network Computing Devices, Inc., Mt. View, CA Lines: 45 In article <10329@cadillac.CAD.MCC.COM> vaughan@mcc.com (Paul Vaughan) writes: >klimas@astro.pc.ab.com wrote: > >Does anyone have any experience, intuition, or statistics concerning >the use of const? Does it really help clear up errors or not? It's >certainly a bag of worms to get a program const correct--it just >ripples and ripples through your code and then you wind up finding a >place in some library or system function where something really should >have been const but can't be changed and you have to cast around it in >the end. So what's the verdict is const worth it? I believe that it is. At one point during the development of my protoize program, I decided that it would be fun to make the program itself cleanly compile with all three of {gcc,g++,cfront}. The first step was to protoize protoize itself. That was easy. I could have just stopped there, but I found some minor bug that having const's all over (in appropriate places) would have alerted me to during compilation. So I started putting in the const's. Indeed, just as Paul says, once you start this process, each addition of one "const" in one place causes you to be forced to add const in several more places. It takes awhile for this ripple effect to settle down. I seem to recall that for about 4000 lines of clean C code (which I understood well, because I was the author) the whole process took me about 3-4 hours or so. That's not too bad, but keep in mind that I had a very intimate understanding of how the code worked to begin with. Inserting all needed const's in somebody else's piece of spagetti (i.e. not your own spagetti :-) could take a lot longer. I'm happy with the result for two reasons. First, I'm getting the compiler to help me a bit more to catch more bugs (or at least potential bugs) at compile time. Second, and perhaps even more important, there is a documentary aspect to having the const's in there. I feel very strongly that source code files are themselves critical pieces of documentation (and sometimes the only ones available :-( and having all of the const's in there will help the next guy to be able to understand and maintain *your* spagetti. Remember. when it comes to crappy code, what goes around, comes around. -- // Ron Guilmette - C++ Entomologist // Internet: rfg@ncd.com uucp: ...uunet!lupine!rfg // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.