Sei sulla pagina 1di 2

MACROS

Macros are special lines/fragments of code which differ from any


other code written in the source files in the aspect that it's not passed
to the compiler (either for the purpose of encoding into machine
instructions, or some intermediate form instructions). Instead, macros
perform textual manipulations on the source code before passing it to
the compiler, where this process preliminary to compiling the source
files is called "preprocessing", and the software component
responsible of doing it is called the "preprocessor". Henceforth,
macros are usually defined as "preprocessor directives", where a
segment of code is replaced by the results of the macro processing
before passing the source code to the compiler. A very valuable
technique to gain a thorough understanding of the operation of macros
in any environment is to learn how to obtained the preprocessed
source code, and see how the macro directives are expanded.
Preprocessor macros, because of their distinctive nature compared to compiled
code, are powerful tools in programming, and that's why the concept of macros
is applied in most programming languages, such as the C programming
language.

Macros should not be confused with other compiled code, and they should be
used only while bearing in mind how they work, namely by modifying the
source code prior to passing it to the compiler. Trying to employ macros to do
jobs that cannot be done before compilation, but rather depends on the
program's compiled state or the execution yields is a common mistake that
beginners make

Its advantages-

The main advantage of using the macro is the speed of the execution of the program (if macro
is not used in the program many times or if the program is small).

The main disadvantage of the macro is it increase the size of the program because the pre-
processor will replace all the macro name in the program by it actual definition before the
compilation of the program

The excessive use of macros for purposes achievable by run-time techniques is not
recommended, and somehow deprecated. Nevertheless, macros sometimes are viable tools
that have no other alternative, such as the case with assertions.
MODULES

A module is a software unit that groups a set of data structures and subprograms/routines,
which are typically cohesive. Modules are entities that are separately compiled by
programmers to make them reusable. This allows programmers to work of different modules
simultaneously. Modules promote two important elements of software programming:

• Encapsulation (also called as information hiding)


• Modularity

These elements make complex programs simpler to grasp. Most programs are composed of
one or more modules that are developed independently. To explain modules in a detailed
manner, we will take the example of the Perl module.

The Perl Module:

A Perl module is a separate component of program for the Perl programming language. As
you know Perl allows many different style of programming. You will find a module written
as object-oriented (like the XML-Parser) or in a procedural style (e.g. Test-Simple). Modules
in Perl language can also be used to change the syntax of the language or for mixing methods.

A collection of one or more modules, including build scripts and documentation, compose a
distribution. The Perl programming community has a huge library of distributions.

Potrebbero piacerti anche