#region pre-processor or not?

  • Thread starter Thread starter John
  • Start date Start date
J

John

I have two books saying different things about the #region directive. One
says that all code within #region does not affect the compilation process
in any way, while the other states that the entire region is marked for a
pre-processor directive which does affect the compilation process.

I was wondering which is accurate? Is #region/#endregion just a text
editor visualization tool with not effect otherwise, or is everything
within the block seen as one big preprocessor command?

TIA
-John
 
there really isnt a preprocessing phase in the compilation process these
were c++ days. the 'pre-processing' phase is now part of the lexigraphical
analyzer portion. code falling within these blocks affect conditional
compilation which means that the text is re-arranged before the compiler
proper sees. so in fact, pre-processing does affect the compilation process.
 
Interesting, because I recently took a c# skills test and I got the following question wrong. I think I answered D



4 The #region preprocessor directive:

a. defines a region of code to be executed before the rest.

b. Marks an area of text with a comment

c. Defines a region of code to be compiled with 'debug on'

d. Marks an area of text to be treated as native call.



I looked through all the documenatation and the best I could figure was it was B.
 
b is probably correct, #region is used to subsection code in the editor, its
a language feature that exists strictly for nicer IDE's.
Its actually the only one I can think of that is there for that singular
purpose.

blasted OE, looses commenting markers when changing from html to plain text,
<g>

-----end post-----

Interesting, because I recently took a c# skills test and I got the
following question wrong. I think I answered D

4 The #region preprocessor directive:
a. defines a region of code to be executed before the rest.
b. Marks an area of text with a comment
c. Defines a region of code to be compiled with 'debug on'
d. Marks an area of text to be treated as native call.

I looked through all the documenatation and the best I could figure was it
was B.
 
John said:
I have two books saying different things about the #region directive. One
says that all code within #region does not affect the compilation process
in any way, while the other states that the entire region is marked for a
pre-processor directive which does affect the compilation process.

I was wondering which is accurate? Is #region/#endregion just a text
editor visualization tool with not effect otherwise, or is everything
within the block seen as one big preprocessor command?

Hi John,

The #region/#endregion preprocessing directives have no effect on the
resulting compiled code. They exist simply for the benefit of IDE's to
group a block of code during editing.

Joe
 
They exist simply for the benefit of IDE's to
group a block of code during editing.

Thanks for the reply. I don't see why microsoft chose this method as
opposed to a more normal one such as a derivation of //, /*, or /// for
regions. Using a preprocessor directive that has nothing to do but make
comments seems so odd. Is there a reason that they didn't use a normal
commenting alternative, instead, for this concept?

TIA
-John
 
John S. said:
Thanks for the reply. I don't see why microsoft chose this method as
opposed to a more normal one such as a derivation of //, /*, or /// for
regions. Using a preprocessor directive that has nothing to do but make
comments seems so odd. Is there a reason that they didn't use a normal
commenting alternative, instead, for this concept?

Although you can add text to the #region directive, that is not a comment,
but is really a description of the region. IMO, a comment would be
additional syntax for expressing what a region does and would not be a good
substitute because you would have to define a region comment standard that
has a begin and end. Also, IMO, a comment is not representative for what a
region accomplishes. The real purpose of a region is to help organize code.

In the IDE, you can use a region to expand and collapse large blocks of
code. This makes navigation and reading code a whole lot easier. An
example of this is when defining a custom collection class in VS.NET. Every
time you implement an interface and press the tab key, VS.NET adds a new
region to your type with skeleton stubs for interface members. By the time
you've completed collection class implementation, you have dozens of
members. The regions that categorize and classify these methods according
to interface make the class a whole lot easiser to navigate and use. This
is just one way that regions can help organize code, which could also be by
member type (events, methods, properties, etc). If all you have is Notepad,
they lack benefit because there is no way to expand and collapse them, but
if you're using an IDE, they are great.

Joe
 
Back
Top