Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
compare webbrowser
Freenet DSL
Who's Online
11 user(s) are online (10 user(s) are browsing encyclopedia)

Members: 0
Guests: 11

more...
browser tip
Unix Befehle
manual of unix befehle
recommendation!
Sponsored
partner

Comparison of imports to includes

This is a comparison of symbol table imports in modern programming languages to the use of #includes in C programming language and C plus plus.

There can be some confusion among C and C++ programmers about how imports work, and conversely among Java programming language programmers, for example, about the proper use of include files. Although, both of these techniques are solutions to the same problem, namely compiling across multiple source files, they are vastly different techniques.

Since nearly all modern Compilers consist of essentially the same stages of compilation, the biggest difference can be explained by the fact that includes occur in the lexical analysis stage of compilation, whereas imports are not done until the semantic analysis stage.

=Comparison=

==Advantages of imports==

  • Imports do not duplicate any lexical analysis effort, which generally results in faster compilation for larger projects.
  • Imports do not require splitting code into separate files for declaration/implementation.
  • Imports better facilitate distribution of object code, rather than source code.
  • Imports can allow circular dependencies between source files.
  • Imports implicitly carry a mechanism for resolving symbol collisions when more than one symbol table defines the same symbol.
  • ==Disadvantages of imports==

  • Imports require a standard mechanism for defining a symbol table in object code. Whether this limitation is truly a weakness is debatable, as a standard symbol table is useful for a number of other reasons.
  • Imports require a method for discovering symbol tables at compile time (such as the classpath in Java). When, however, there exists a standard method for doing this, this is not necessarily any more complicated than specifying the locations of include files.
  • When circular dependencies are allowed, semantic analysis of several interdependent source files may need to be interleaved.
  • Unless the language includes support for partial types, languages with imports instead of includes require all source code for a Class (computer science) to be in a single source file.
  • ==Advantages of includes==

  • With includes, there is no interdependence between source files at the semantic analysis stage. This means that at this stage, each source file can be compiled as an independent unit.
  • Include files, used in combination with other preprocessor features, allow for nearly arbitrary lexical processing.
  • Although the practice is not widespread, includes can provide rudimentary support for several modern language features (such as mixins and Aspect-oriented programming) if the language itself does not support them.
  • Includes are not part of the syntax of the underlying language, but rather part of a preprocessor syntax. There are disadvantages to this (another language to learn), but there are also advantages. The preprocessor syntax, and in some cases include files themselves, may be shared among several different languages.
  • ==Disadvantages of includes==

  • Includes and the requisite preprocessor can require more passes in the lexical analysis stage of compilation.
  • Repeated compilation of header files included multiple times in a large project can be notoriously slow. This can be mitigated, however, through the use of precompiled headers.
  • Proper use of header files, particularly declarations of global variables, can be tricky for beginners.
  • Because includes generally require the location of the included file to be specified in the source code, environment variables are often needed to provide part of the include file path. Even worse, this functionality is not supported in a standard way across all compilers.
  • =Conclusion=

    In general, the use of preprocessors has fallen out of favor, and the problems with includes are often cited as a reason for not including a preprocessor in a new language. Most modern language designers prefer to take the route of imports.