Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!sunic!Urd!newsuser From: newsuser@lth.se (LTH network news server) Newsgroups: comp.lang.c++ Subject: Re: Some "guidelines" for coding in C++ Message-ID: <1989Oct21.141916.2611@lth.se> Date: 21 Oct 89 14:19:16 GMT References: <1148@aber-cs.UUCP> Reply-To: dag@Control.LTH.Se (Dag Bruck) Organization: Dept. of Automatic Control, Lund Inst. of Technology, Sweden Lines: 47 In article <1148@aber-cs.UUCP> pcg@cs.aber.ac.uk (Piercarlo Grandi) writes: >Always prefix globals with ::, members with this->, static members with name:: > > All global identifiers should be prefixed with ::, and all > members with this->; this avoids some very hard to catch bugs. I haven't been bitten by this yet -- on the other hand, I try to write very simple programs. I would find all the "::" and "this->" to make the code less readable, hence more difficult to maintain. > Always put the data members first in a class I find the operations on a class (primarily the member functions) much more important than the actual data representation; I therefore put all member functions in front of the data members. In fact, I have many times wanted to hide the data members completely, which unfortunately is not possible without indirection. > If > necessary, have two private:, protected: and public: sections, one > each for data and procedure members. This is quite useful. I normally have the following order: 1. Public functions 2. Protected functions 3. Public data. 4. Protected data. 5. Private functions. 6. Private data. This discussion is of course much matter of taste -- your's or your manager's. Try different approaches! > Always specify const in all places where it can be. > Always have few, explicit inlines, outside the class definition, > always static. I think these are the most important of Piercarlo's rules. Dag Michael Bruck -- Department of Automatic Control Internet: dag@control.lth.se Lund Institute of Technology P. O. Box 118 Phone: +46 46-108779 S-221 00 Lund, SWEDEN Fax: +46 46-138118