There are several methods to producing code suitable for different
generations of computer:
Method A: Using generic code
This is the preferred method of coding.
/* This code runs on all generations of computer */
genericcode
Pros
- Code is lightweight, because there is only one code branch
- Compiled executables are lightweight, since only code relevant
to the machine is included
- Program behaves the same on all machines
- Programs are easy to debug because the same code is used on all
machines
- Programs are portable across machines
Cons
- Machine specific features cannot be utilized
Method B: Using conditional branches
if machinetype=A then
do this
else
do that
endif
Pros
- Program is portable across machines
- Machine specific features can be utilized
Cons
- Code is bloated because there are multiple code branches
- Code is difficult to debug due to redundancies and differences
in behaviour across machines
- Programs are bloated and contain redundancies that are not ever
utilized on the machine
- Programs may behave differently depending on which computer they
run on
Method C: Using conditional compilation
#IF MACHINETYPEA
do this
#ENDIF
#IF MACHINETYPEB
do that
#ENDIF
Pros
- Programs are lightweight, since only code relevant to the
machine is included
- Machine specific features can be utilized
Cons
- Code is bloated because there are multiple code branches
- Code is difficult to debug due to redundancies and differences
in behaviour across machines
- Programs are not portable and require recompilation when moving
across machines
© Copyright 2008 Mark
Hobley