Re: Languages

From: Christian Loth (sg618lo@unidui.uni-duisburg.de)
Date: 03/10/99


Greetings,

Am Mit, 10 Mär 1999 schrieb Jason Wilkins:
> 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.

Yes, but as far as I understood George's initial criticism that this is
exactly what he criticized...you need to open a new block {} for
that.

>
> The real reason is readability and race conditions.  Declaring a variable

Readability...wasn't that exactly the point? Like the spaghetti code
of Basic? I don't understand the race conditions however, for thread
support isn't an integral part of C++ (Objective C has it, IIRC).

> 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

Ah okay, now I understand ... you mean that a variable might
contain an illegal value or no value at all. I agree.

> 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.

Actually isn't the solution of a new scope a 'half-way'-solution
to 'place your variables where you want them'? So placement
for classes with constructors (not so for integral types) is a
performance issue, not?

But I also see your point with illegal values. I think both reasons
are valid.

- Chris

--
Christian Loth
Coder of 'Project Gidayu'
Computer Science Student, University of Dortmund
sg618lo@uni-duisburg.de - chloth00@marvin.cs.uni-dortmund.de


     +------------------------------------------------------------+
     | 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