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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,f292779560fb8442 X-Google-Attributes: gid109fba,public X-Google-Thread: fac41,af40e09e753872c X-Google-Attributes: gidfac41,public X-Google-Thread: 1014db,30e368bdb3310fe5 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,30e368bdb3310fe5 X-Google-Attributes: gid103376,public X-Google-Thread: 1008e3,30e368bdb3310fe5 X-Google-Attributes: gid1008e3,public X-Google-Thread: 10db24,30e368bdb3310fe5 X-Google-Attributes: gid10db24,public X-Google-Thread: f8c65,30e368bdb3310fe5 X-Google-Attributes: gidf8c65,public From: willer@carolian.com (Steve Willer) Subject: Re: Hungarian notation Date: 1996/05/23 Message-ID: <31a47e13.49044301@sqarc.sq.com>#1/1 X-Deja-AN: 156331574 sender: news@sq.com (News Administrator) references: <31999F43.41C67EA6@scn.de> <319D2278.3F9A@netonecom.net> <4nr50r$jo2@ringer.cs.utsa.edu> <4nsgct$c3l@cville-srv.wam.umd.edu> <4nvn6s$c83@gaia.ns.utk.edu> <31a3aed9.441307817@sqarc> <4o1928$ngv@goanna.cs.rmit.EDU.AU> organization: Carolian Systems, Toronto ON newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.edu,comp.lang.eiffel Date: 1996-05-23T00:00:00+00:00 List-Id: ok@goanna.cs.rmit.EDU.AU (Richard A. O'Keefe) wrote: >willer@carolian.com (Steve Willer) writes: >>Neato! So I guess there is one and only one solution to the problem of >>invalid pointers! > >Let me put it this way: > IUnknown::AddRef >and IUnknown::Release >are _not_ the solution. Certainly, I am far from being COM's biggest fan. But the point I'm making is that garbage collection is not a perfect solution, nor is it the one and only solution. No matter what the scheme (gc, ref-counting, etc.), pointers can still get scrambled. I have personally been quite successful with setting rules of ownership and sticking by them. With the primary use of auto_ptrs and references, I don't have problems with dangling pointers and the like. HOWEVER, in order to properly use these different argument types without problems, I either need a perfect memory or a good naming convention. I don't have a perfect memory. This setup won't work well in C, but it works very well for me in C++. Here's the relevant part of my own coding standard: 1. Function argument types When designing function interfaces, keep these points in mind: a) All "input" arguments should be first, followed by "input/output" arguments and then followed by "output" arguments. It may be necessary to adjust this order to allow consistency with functions of the same name, and default arguments may also force a reordering. b) Arguments must be declared const as often as possible. In other words, restrict the argument as much as you can. c) In C++, if ownership of an object is being transferred, the argument must be an auto_ptr passed by value. If ownership is not being transferred, then the argument must be a reference. The only exception to this is when it must be possible to give a NULL (obviously, the argument should be declared as a pointer in this case). However, rethink the necessity of a NULL-compatible argument before using a pointer argument.