Re: [Fresco-devel] Suggested addition to Coding Style-guide
Gabriel Dos Reis <[email protected]> 13 Apr 2003 01:14:53 +0200
| Newsgroups | gmane.comp.video.fresco.devel |
|---|---|
| Organization | Integrable Solutions |
| Message-ID | <[email protected]> |
Neil Pilgrim <[email protected]> writes: | Gabriel Dos Reis wrote: | > Neil Pilgrim <[email protected]> writes: | | > | class some_type; | > | namespace type_space | > | { | > | class some_type; | > | }; | > | /* ... */ | [...] | > | In quite a few instances (if not a *lot*!) we don't currently do this; | > | it seems like a good common idea, so assuming no discussion to the | > | contrary it'd be good to add it to the coding guide. Oh, and implement | > | it ;) | [...] | | > I would suggest you don't repeat declarations all over the places as | > suggested above. | > While that might be seem a reasonable practice in C, it is recommanded | > for C++ coding that you : | > | > (a) include the appropriate header files | > (b) design a forward-declaration header and do (a) | > | > The point is that C++ tends to be very picky about declarations and | > name-lookup are already complicate; it is better to include a heade | > file that provides the "true" declarations in every translation unit. | > | > You'll also find that what you're proposing does not scale to standard | > types and functions. It is therefore preferable to have a coding | > style that apply both to standard headers and Fresco entities. | | This may be ideal, but then surely you either a) end up having a huge | number of files (one per previous header?) b) one per section? Note necessarily. Usually, one creates a file with forward-declarations of logically *releated* classes and types. [...] | Maybe build times cannot be drastically reduced with this method, but in | my limited experience it can be very useful in limiting the dead time | during development. When build times is really an issue, I believe using that using things like precompiled headers helps much more than declaring by hand which entity one uses. At least, that is my exprience with large projects. A frightening downside of forward declaring "by hand" is the same as why you don't want code-duplication: Every minor change needs to be done at zillions of places, whereas including a forward declaration header keeps the changes in one place. -- Gaby