POV-Ray : Newsgroups : povray.binaries.images : My first isosurface. ~41kbu : C++ vs C (was: Re: My first isosurface. ~41kbu) Server Time
3 Oct 2024 13:22:28 EDT (-0400)
  C++ vs C (was: Re: My first isosurface. ~41kbu)  
From: Thomas Willhalm
Date: 14 Feb 2000 08:38:46
Message: <qqmwvo7vr89.fsf_-_@schlatt.fmi.uni-konstanz.de>
David Parrott <Xam### [at] quayles1demoncouk> writes:
> 
> OK, after reading that I like practically everything that I see except
> one thing. I do not like this declare variables anywhere business. I
> feel that this would lead to scrappy and difficult to follow code, when
> declared at the beginning of a block you can see which variables are
> declared easily. I feel that a code block is then easier to follow.

When I switched from (Turbo) Pascal to C++, I had the same feelings.
That's why I can completely understand you. However, time and practice 
have changed my opinion on this matter. 

There is no need to see variables that are only used inside of loops or if- 
statements. If you can declare them inside that block, you can distinguish
between variables that are visible inside the whole function and those
that are only visible inside parts of it. This may save you from some 
trouble and reminds you to remove the variable declaration if the block is 
removed.

Another possible usage is that you can now always initialize a variable
when it is declared. This prevents using uninitialized values.
If you have to declare all variables at the top of the function, it isn't
always possible to initialize them with meaningful values.

But of course you aren't forced to declare variables in the middle of the
code. If you like it, you can still declare them in C-style manner.

Thomas

-- 
http://thomas.willhalm.de/ (includes pgp key)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.