Re: Batch file for Visual Studio build, was Why not u se BUILD [was Re: Errors while

I find the ability of placing declarations close to the point they’re needed
a great feature of C++. It immensely adds to the readability of the code.
And the important point that functions now don’t have global names, but are
qualified by the classes to which they belong, is a great help to
modularization. Just like pdo.blah and irp.blah are two different pieces of
data, likewise, pdo.dump() and irp.dump() are two very different functions.
You can still have a global dump() function: use ::dump() instead.

The same thing goes with operators. If a and b are numbers, a+b is a number;
but I may want to use + for string concatenation, in which case a+b will be
a string. Or maybe a and b are vectors, in which case a+b is a vector sum.
And so on. The key concept is that operators and functions are defined
within classes, they’re no longer by definition globals.

And if you need to search for myadd(), or to figure out where this or that
method is declared, just use your MSVC browser and you’ll get to it jolly
fast. But mind you, you only say myadd() unqualified if you’re inside a
member function of the class of which myadd() is also a member. If you’re
using some other class’s myadd(), you’d say otherclass.myadd(). If you’re
using a global myadd(), you’d better practise safe programming and say
::myadd() instead.

The bottomline is, C++ is not C, it’s a different language which has
back-compatibility with C if one doesn’t use any object orientation. If you
program C++ the same way you program C, well, you deserve what you get !

Alberto.

-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Friday, October 18, 2002 7:17 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Batch file for Visual Studio build, was Why not u
se BUILD [was Re: Errors while building samples of DriverStudio in Windo
ws XP]

RE: [ntdev] Re: Batch file for Visual Studio build, was Why not use
BUILD [was Re: Errors while building samples of DriverStudio in
Windows XP]>you can write C++ style code with your C ( define local
variable when you need it instead of

define them all in the begging of you function).

First, this is ANSI C feature. Second, some version of WinDbg bugs on
such variables, so, I quitted writing such code about 2 years ago to
avoid WinDbg problems.

I always declare everything in the beginning of the function, not
block, and I also always end KdPrints with \r\n - this is to work
around the SoftICE issue, even though I do not use it (other
developers at SCI use it).

So, the coding habits follow the tool’s problems and make workarounds
for them :slight_smile: As about declaration - can somebody think not only on
him/herself, but on others who will read this code then? Declarations
in the beginning of the function have disciplining effect. “First
declarations, then all other stuff”. C++ style declarations do
irritate and distract attention, but yes! they are a saving while
typing!

Most C++ features are, in fact, a way of simplifying typing, at the
cost of code readability. If any non-trivial class has “operator +”,
and I see “a + b” in the code, then I must browse the source of this
class and all its bases for “operator +” declaration!
If this would be explicit call MyAdd(a, b) - just search for “MyAdd(”.
Multiple functions with the same name is another PITA. Too easy for a
bug to sneak in due to a bit other type. Much harder to read the code
written by others.
Even distinguishing between a method call or global function call
needs some more time.

Even dirty C code (like Linux’s SCSI stack) is more or less
comprehendable. Not so with dirty C++ code. C++ is just
contra-ergonomical language.

Max


You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to %%email.unsub%%

The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.