On Wed, 10 Mar 1999, Christian Loth wrote: > But in C++ this 'freedom of variable placement' is based on a > performance consideration. Imagine you have three or four pretty > complex classes, with pretty complex contructors. Now there's > a function in your code where you need to use instances of all > those classes. > > In C style you would declare them all at the beginning...but that > would also include the costs of constructions for your classes... > ...whereas if you declare them where you actually need them you > only have those costs if you need those costs. Wrong, try again, you can declare variables exactly where you need them in C as well. The real reason is readability and race conditions. Declaring a variable right before you use it is more correct than having it at the top. The race condition comes from the possibility that a person may not have all the information they need to initialize a class at the top of a function, so rather than require them to open a new scope when they are ready (which would produce gross looking source code) just let them do stuff before the declaration. performance really isn't an issue, since that was already solved by being able to only declare variables at the top of scopes in which they are needed. -- The Phoenix - President of The Artistic Intuition Company Caelius * Zen-X * Mirror Reflex * Runica * X-Domain * Infinite Realms http://www.io.com/~fenix +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST