Re: Include Statement
- From: "Herfried K. Wagner [MVP]" <hirf-spam-me-here@xxxxxx>
- Date: Tue, 5 May 2009 21:27:53 +0200
"Mike" <unknown@xxxxxxxxxx> schrieb:
Maybe I missed this because I can't find it, but is there and "include sourcefile" statement in VB.NET? example
'MainProgram.vb
imports system
module module1
#include "some_common_stuff.vb"
#include "useful_classes.vb"
sub main()
end end
end module
I mean, this is standard stuff in the other .NET languages? No?
No, there isn't, because it's not necessary in languages like VB and C#.
Who says? Gawd, I hate this closed indset.
The VB compiler works in an other way than C/C++ compilers, for example.
Typically includes have been used in C/C++ to make functionality defined in another file available in another file (I do not use C/C++ terminology here because I am not sure if you are familiar with C/C++). This is done automatically by the VB compiler, so there is no need to do it manually.
Types defined in another source file belonging to the project can be accessed *directly* if the namespace they reside in is imported and the types' visibility settings grant permission to access the types/members. No need for forward declarations!
So why do other .NET, like C++ languages support a simple include concept? Including VB ASPX files?
The C++ compiler doesn't do all the work for you which the VB compiler does. ASP.NET applications differ in structure from the typical project which is compiled into one binary file.
I mean, this is yet another case where VB.NET attempts to inherit standard compiler concepts, but fails to do go all the way, only does for a few things. For example, existing compiler directive
#const USE_VERSION = 1
#if USE_VERSION = 1 then
some v1 code
#elseif USE_VERSION = 2 then
some v2 code
#else then
#error "USE_VERSION not defined"
#end if
Very powerful ideas for programmers. Don't tell me it "isn't necessary."
This is supported in VB.NET because it makes perfect sense even in VB.NET!
If VB.NET support these compiler directives, there is no reason why it couldn't do #include.
I already mentioned the reason why it is not necessary. In C/C++ '#include' is the typical way to make information from one file available to another one. In C/C++ you even have to write forward declarations and so on because the help the compiler provides in this regard is rather limited compared to the work the VB compiler does.
BTW, the '#include' concept of C/C++ is rather low-level and not very comfortable to use.
Adding a standard #include concept isn't going to change anything regarding name spaces and that wouldn't be the purpose, but in fact, it could very useful in quickly creating new namespaces out of include files
namespace MyNewNameSpace
#include "class_dispose.vb"
#include "class_music.vb"
#include "class_whatever.vb"
end namespace
Just add the namespace declaration on each of the files. No need to use text-based inclusion of other files. Code duplication, which was one of the top reasons for using '#include' in C/C++ isn't required and it would not work in VB.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
.
- Follow-Ups:
- Re: Include Statement
- From: Mike
- Re: Include Statement
- References:
- Include Statement
- From: Mike
- Re: Include Statement
- From: Herfried K. Wagner [MVP]
- Re: Include Statement
- From: Mike
- Include Statement
- Prev by Date: set printer to gray scale
- Next by Date: Re: Include Statement
- Previous by thread: Re: Include Statement
- Next by thread: Re: Include Statement
- Index(es):
Relevant Pages
|