Вы находитесь на странице: 1из 4

Selecting a Programming Language

for Your Project

David Naiditch
Raytheon Systems Company

INTRODUCTION added scveral new pragmas [compiler directives] and


special packages [Interface and its child packages] that
In 1997, the mandate was dropped that the Ada enablc Ada 95 code to easily interface with other
language had to be used in all DoD projects. Since then, languages.)
software managers have had more freedom to choose As Table 1shows, there are many important
which programming language to use on their DoD differences between Ada 95, Ada 83, C+ +, C, and Java.
projects. With this new freedom has come new The comments in the right column of the table provide
responsibilities. Too often, discussions about what some rationale for the rankings. A full discussion of each
language to selcct break down into emotional appeals for category in Table 1, on next page, is beyond the scope of
one’s favorite language. Instead, a fair and rational process this brief paper, but some issues are discussed
should be established that bases the choice of a subsequently when I cover common misconceptions.
programming language on issues related to customer Although each programming language has its own
needs and business goals. In particular, for large projects, a strengths and weaknesses, the reason for choosing a
language should be selected according to objective particular language may ultimately be based on factors
evaluation criteria, a system of priorities, and an overall having nothing to do with the tcchnical merits of the
scoring algorithm. This selection process should be done language itself. (This is yet another reason that the Ada
by those having a working knowledge of the languages mandate was dropped.) Such factors may include thc
undcr consideration. The winning language that emerges availability of compilers for the hosthargct, the maturity
from such a process might not be the language initially and efficiency of available compilers, the availability of
considered as the obvious best choice. For projects that are programmers who already know the language, whethcr the
too small to afford the time and effort needed to evaluate language can easily interface with existing systcms such as
different languages, the choice of language might be made graphical user interfaces or data bascs, the existence of
at the product line level or higher. legacy software written in a specific language, or how well
For most new DoD software projects that need a the language fits in with adopted commercial-off-the-shclf
general purpose high-level language, Ada, C, or C + + are (COTS) products.
the main contenders, with increasing attention paid to the A few common misconceptions that may affcct the
new language celebrity, Java. (In this paper, “Ada” refers choice of a programming language are listcd below.
to both Ada 83 and Ada 95.) Furthermore, multilanguage
systems seems to be getting increasingly popular. As a
MISCONCEPTION 1:
result, companies such as Rational, Aonix, and Green Hills
THE GOVERNMENT DROPPED THE ADA
offer integrated multilanguage programming
MANDATE BECAUSE ADA IS A DYING LANGUAGE
environments. (In response to this trend, Ada 95 has

When, in 1997, the Honorable Emmett Paige, Jr.,


Author’s Current Address: Assistant Secretary of Defense for Command, Control,
Raytheon Systems, Company, RE Building, R 0 1 M / S A521.2Mx) East Imperial Communications and Intelligence, dropped the Ada
Highway, El Segundo, CA 90245, USA. mandate, he made it very clear that this action should not
Based on a presentation at DASC ’98. be seen as the government’s lack of commitment to Ada.
088V8985199 $10.00 0 1999 IEEE He felt that the mandate became a “contentious point of

IEEE AES Systems Magazine, September 1999 11


Table 1. Language Comparisons

Feature Ada95 Ada83 C++ C Java Comments


lhilt-in support for Excellent Very None None Good For C or Ct+,concuircnt programming
concurrency Good requires calls to nonportable and low-levcl
(multithreading) operating system (OS) services.
Full support of object- Yes No Yes No Yes Ada 81 has most, but not all object-oriented

Full support for Yes Yes Yes Yes No To usc lava, object-oricntcd programmiiig
procedural-based must be fully embraced.

soltwarc engineering

features such as enumeration typcs and


recordslstructurcs. Ada R3 lacks pointers to
subprograms and stack-allocated objects and
OOP features. C++ lacks concurrcncy

virtual machine. not Sroin thc language itself.


C++ implementations ?till do not Sully
conform to tlie rcccntly introduced I S 0
standard.
Lifc cycle costs Excellent Exccllent l’oor Poor Good Historic data show that, linc pcr line. Ada
code is about ha11 the cost of C or C++ codc
(see reference to Zeigler’s article).
Safety and reliability Excellent Excellent Poor Poor Vcry Ada catches iniany bugs at compile time and
Good then others at iuntiiiie. Ada is the most
strongly typed language and guards against
dangling pointers.
Ease of rcusc I Excellcnt Excellcnl Excellent Poor Good Ncither Java nor C hiivc gcncrics/lcmplntes.
C’s macro expandcr is a poor substitute.
Support for intcr- Very Poor None None None Ada 95 provides several praginas (compiler
language communication Good directivcs) and packages for this purpose.
Language support Good Fair Good Very Excellent Many Ada vendors have trnnsitioiicd to Ada
Good 95 and consider Ada 83 to be obsolctc. Ada
host and target compilers are readily available
for mainstream microprocessors. but may be

resentment,” and that Ada was fully capable of standing on checks.) Java, however, usually runs considerably slower
its engineering merits. because it makes cxtensive use of dynamic (heap allocated)
In fact, Ada is very unlikely to go away in the data structures and has automatic garbage collection, and
foreseeable future. The DoD has a tremendous invcstment because the gcnerated bytecode is typically interpreted.
in Ada. Over 50 million lines of Ada code have been (The last problem can be mitigated if a “just-in-time” [JIT]
developed €or warfighting systems. Many of thcse systems compilcr, or better yet, a native Java compiler, is
will be used well into the next millennium. Furthermore, available.) Of course, efficiency can significantly vary from
Ada will continue to be chosen for its reliability and lower one implementation of a language to another.
development/maintenancecost, both of which arc so Furthermore, different compilers are optimizcd for
important for large, long-lived software systems (see different language features.
Misconception 11).
MISCONCEPTION 3:
MISCONCEPTION 2: VERY TERSE SOURCE CODE RESULTS IN VERY
C IS THE MOST EFFICIENT LANGUAGE EFFICIENT OBJECT CODE
SINCE IT IS CLOSER TO ASSEMBLY CODE

C is not necessarily the most efficient language. The only guarantee is that very terse codc results in
When runtime checks are turned off, Ada code may run unreadable and, therefore, unmaintainable code. Do not
about as fast as C . (Standard C does not perform runtime assume, for example, that this C code

I2 IEEE AES Systems Magazine, September 1999


if ((A= B) = = C ) C += 2; compiler. For instance, Intermetrics and Aonix offer Ada
95 compilers that generatc Java bytecode.
executes any fastcr than Although Java’s portability does not havc that much
to do with the language itsclf, Java does addrcss portability
A = B; through predefincd numeric types with specified sizes and
if(A = = C ) C = C + 2; formats. Thus, type “int” is always a 32-bit signed integer
typc, whereas in C and C+ +, int can be of any size. If any
Interestingly, Java’s syntax is a somewhat cleaned-up of Java’s numcric types are not supported by the target
version of C+ +’s syntax. For instance, Java climinatcs the architecture, then that type must be implemented in
possibility of confusing an assignment with a test for equality software, which could significantly degrade pcrformancc
in a conditional. Thus, Java rejects this code (see Misperception 2). In Ada, a programrncr can sclcct a
numcric type by range and/or precision rather than only by
if (A = B) name, which guarantees that the numeric type has the
range and precision that is required.
However, Java embraces C‘s error-prone syntax for
the switch (case) statemcnt, where a “break” can be MISCONCEPTION 7:
accidcntally omitted. USING OPERATING SYSTEM (OS) SERVICES FOR
CONCURRENT PROGRAMMING IS JUST AS GOOD
MISCONCEPTION 4: (IF NOT BETTER THAN) USING SPECIAL LANGUAGE
EASE OF CODING IS A MAJOR ADVANTAGE CONSTRUCTS

Unlike Ada and Java, C and C+ + do not provide


Ease of coding is not a major advantagc comparcd
constructs for writing concurrent code (codc that can do
with ease of reading. For complex code that must bc
more than one thing at once). To write concurrent
maintaincd over many years, maintcnance costs typically
run 70% to 90% of the softwarc life cycle costs. Because software, C and C+ + programmers often rely on OS
one must be ablc to read code in order to maintain it, the services such as semaphores that arc nonportablc, low
extra effort taken in dcveloping readable codc amply pays level, error pronc, and difficult to debug. For examplc,
off. And don’t forget that thc annoyancc of excess key with scmaphores, there is a risk of locking (scizing) an item
strokcs is no excuse for writing unreadable code, not even and then forgetting to unlock (release) it when one is
for two-finger typists. finished with it so that other tasks can access the itcm. In
contrast, Ada 95 allows protected operations to be defincd
that automatically provide mutually exclusive acccss to a
MISCONCEPTION 5: protcctcd item. This featurc climiilates the risk of having
SOFTWARE SHOULD BE EASY TO COMPILE an unbalanced IocWunlock. (For hard real-timc programs
that cannot even afford the overhead of protccted types,
Softwarc should not nccessarily be casy to compile. Ada 95 offers portable semaphore services.)
As many bugs as possible should be caught at compilc
time, since thc sooner a bug is caught, the easier and MISCONCEPTION 8:
cheapcr it is to fix. Ada, for example, catches many errors PROCEDURAL-BASED PROGRAMMING HAS BEEN
at compile timc (for example, calling subprograms with the REPLACED BY OBJECT-ORIENTED PROGRAMMING
wrong type or number of parameters) than other languages
catch at runtime, or not at all. As a result, Ada code is Although the programming world has largely gone
harder to compile than, for example, C code, but once objcct-orientcd, applications do exist (for example,
compiled, many potential errors have been eliminated. cmbedded real-time or scientific applications) whcre
procedural-based programming seems morc natural. In
MISCONCEPTION 6 Ada 95, the languagc features that support object-oriented
JAVA IS A GREAT LANGUAGE BECAUSE THE SAME programming are distinct and can be used separately.
CODE CAN RUN ON WINDOWS 95, SOLARIS, UNIX, Therefore, Ada 95 programrncrs are free to selcct thosc
MACINTOSH, OR JUST ABOUT ANY PLATFORM object-oriented featurcs they want without being forccd
into fully embracing the objcct-oriented methodology. In
Java’s platform independence is wonderful (although contrast, Java only supports object-oriented programming.
a bit overstated). However, this independence derives not so Java cannot be used for proccdural-based programming.
much from the Java language itself, but from the ability of (In Java, even exceptions and thrcads are defincd in
the Java compiler to generatc Java bytecode that can be +
object-oriented terms.) C+ is like Ada 95 in that it does
interpreted on any machine with a Java-enabled web not force programmers to embrace object-oriented
browser such as Netscape or Internet Explorer. Note that programming. However, object-oriented features of C+ +
Java bytccode does not havc to be generated by a Java are not as distinct as those of Ada 95. For instance, data

IEEEAES Systems Magazine, September 1999 13


encapsulation, which is needed for creating abstract data Consider, for example, the use of pointers. In C and
types (called private types in Ada), cannot be performed C+ +, pointers can point willy-nilly to any address. Not
without introducing a class, which is a central feature of surprisingly, the misuse of pointers is responsible for the
object-oriented programming. +
majority of C and C+ programming errors. Often
pointers end up pointing to the wrong data or to items that
no longer exist. Java takes a Draconian approach to this
MISCONCEPTION 9:
problem of pointer abuse by not allowing programmers to
JAVA IS SMALL, SIMPLE, AND EASY-TO-LEARN
explicitly declare pointers! In Ada 95, pointers are flexible,
but also quite safe. Pointers can point to heap allocated
Even though Java is a small and simple language, it objects (as in Ada 83), to stack allocated objects, and to
has some subtle features and includes a huge library of sub-programs. Checks are automatically made (mostly at
over 150 classes and interfaces. It takes considerable effort compile time) to guarantee that (in the absence of
to determine which classes to use and how best to use “unchecked Programming”) a pointer does not point to an
them. Programmers accustomed to large languages such as object of the wrong type, or point to a stack allocated
+
Ada and C+ often find that Java is too small. For object or sub-program that no longer exists.
example, Java is missing local constants, method
parameter modes, enumeration types, records/structures, MISCONCEPTION 11:
operator overloading, variant records/unions, explicit IN TERMS OF LIFE CYCLE COSTS, IT DOES
pointers, fixed-point types, unsigned integer types, range NOT MATTER WHAT PROGRAMMING LANGUAGE
constraints, the goto statement, and generics/templates. IS CHOSEN
Somc of these features were undoubtedly omitted in the
interest of simplicity, portability, or security, but not all of Various studies have shown that the choice of
these omissions are easy to justify. programming language does impact life cycle costs. Such
In general, for small languages to be effectively claims, however, are difficult to substantiate. Part of the
used, programmers often need to write code that simulates difficulty is that large projects are never done in parallel
a missing language feature, or to rely on tools or practices with different languages, but with all other factors held
that are external to the language itself. For instance, Ada constant. Perhaps the study that best approaches this ideal
defines a basic library manager that prevents an executable was done by Dr. Stephen Zeigler of Verdix (now Rational
module from ever being built from out-of-date Software Corporation). Dr. Zeigler based his study on
components. Other languages obtain this capability records kept at Verdix documenting all software changes.
through the use of a Make utility and the careful use of Although these records were not intended to be used to
naming conventions. However, as a result, portability is compare the development costs of Ada and C, they turned
lost and complexity increased, since the proper use of such out to be very useful because few factors varied besides the
languages depends on nonstandardized utilities and language being used: The same 60 programmers were
practiccs that exist outside the language. Thus language developing code in both Ada and C, the same work
complexity should not be considered in isolation, but as environment was used, the same debugging tools, same
part of the software engineering environment. editors, same testing tools, and the same design
methodology. Most of these programmers had masters
degrees in computer science, and the more experienced
MISCONCEITION 10:
programmers tended to work more in C. When first hired,
COMPUTER LANGUAGES SHOULD GIVE
75% of the programmers knew C, while only 25% knew
PROGRAMMERS THE FREEDOM TO DO WHAT
Ada. Despite the bias in C‘s favor, Dr. Zeiglcr showed that
THEY WANT TO DO
the cost of coding in Ada is about half the cost of coding in
C. This difference in cost resulted because code written in
This libertarian view is also held by those who resent Ada contained 70% less bugs discovered before product
the government forcing them to wear a motorcycle helmet. delivery and 90% less bugs discovered after product
Without a doubt, Ada, and to some extent, Java, are delivery. (As discussed under Misconception 5, the later a
“paternalistic”languages that attempt to protect bug is caught, the more expensive it is to fix.) Dr. Zeigler
programmers from themselves and other programmers. In expects the cost of C to be even more pronounced in other
a world where all drivers and programmers are perfectly organizations, because Verdix had the advantage of
rational and sober, such paternalism may seem understanding common C problems and enforcing
unnecessary. However, on the freeways populated by thorough software testing procedures. Interestingly, C + +
maniacs, and in the real software development world bugs were running even higher than C bugs. Dr. Zeigler’s
where mind-bogglingly complex programs are being paper, “Comparing Development Costs of C and Ada,”
maintained over many years by gaggles of programmers, can be obtained at
such optimism is unwise. http://sw-eng.falls-church.va.us/AdaIC/docs/reports.

I4 IEEE AES Systems Magazine, September 1999

Вам также может понравиться