College students are sometimes taught only a single programming language in detail. This limits their exposure to different language syntax/semantics, as well as approaches to problem solving. Every programming language was originally designed for a specific purpose, and, as such, tends to promote its own unique way of looking at, and solving, a problem.
Understanding just a single language promotes solutions that only approach a problem from a single perspective. Knowing multiple languages allows the problem to be looked at from a variety of perspectives so that multiple solutions can be compared and the most natural solution for the problem can be selected.
Say, for example, all you have is a hammer. In this case, both nails and screws will be best inserted with a hammer. However, if you also have a screw driver, then there is an alternate solution for inserting the screws, and the best tool can be selected for the task at hand.
Languages to solve problems
Programming languages are designed to either solve a specific class of problems or support a specific methodology, each encouraging students to look at a problem from a particular perspective.
FORTRAN , for example, was designed to help solve mathematical problems. It can be an ideal language to use for purely mathematical problem solving. COBOL was designed to help solve business data or form storage and manipulation.
The C language was designed to aid in operating system implementation and has features that allow for direct mapping to, or manipulation of, the underlying hardware.
C++ was designed to take a problem-specific language, C, and add Object Oriented programming support. It is thus a mix of both problem solving capabilities and methodological support.
The Ada programming language was designed to provide reliable operation with an emphasis on type safety, scalability and maintainability.
The Java language was designed to provide Object Oriented methodological support and portability. Scripting languages are, in general, designed to allow for very quick solutions to small problems. This list of programming languages can go on and on.
Multiple languages allow multiple solutions
Introducing students to a variety of languages helps them see each language’s advantages and disadvantages in helping to solve problems.
The C language can be used to teach how to interface to, and better understand, the underlying hardware that the software will run on. There is an advantage in some cases to being able to directly map a problem to the underlying computer, such as specifying where devices are located, or directly mapping a structure to memory. The student will also learn the disadvantages of such a language. Languages that allow direct mapping to the hardware tend to be loosely typed, permitting integers to be used as pointers and vice versa, making logic errors much harder to detect.
The Ada language can be used to give students an understanding of how to map a problem directly to a corresponding solution. Ada has powerful built-in typing capabilities, separation of specification from implementation, generic templates, and built in concurrency/threading support (tasks), to name just a few features. Powerful type constructs allow the problem entities (objects, control threads, etc.) to be directly modeled in the solution.
Separation of the specification from the implementation allows for information hiding to aid in portability to different computers and maintainability as the implementation changes over time. Ada is also a strongly typed language that will teach a student the advantages of the compiler catching errors (such as treating a pointer as an integer, which is possible in C) so that they do not end up being run-time logic errors later on.
There are of course disadvantages as well. An Ada program may take slightly longer to write, as a student must specify the types of all variables prior to their usage. Thus there is a cost for static error detection, but this tends to reduce the time that would later be spent debugging an application.
Java may be a good language for students to learn for directly mapping an Object Oriented (OO) methodology into a programming solution. Its virtual machine implementation provides some type safety and also portability (it allows the solution to ignore the underlying computer). On the other hand, Java tends to be clumsy for problems that are not naturally object-oriented.
Further, Java’s thread model is low-level and error-prone, and the language’s stated objective to hide machine details is an obstacle for low-level and real-time applications where such details are intrinsic to the problem.
Multiple languages encourage a solution choice
While all programming languages excel in solving problems for which they were specifically designed, they tend to provide less natural solutions for more diverse problem areas.
For example, languages lacking effective dynamic allocation / reclamation facilities will encourage programmers to represent lists by statically-sized arrays. Languages with good dynamic memory control allow these structures to be modeled in a more flexible way, using pointers and linked lists.
The language choice can thus influence whether the programmer views all lists as static objects that must have a fixed number of items or alternatively as dynamic objects that have no bounds. This representation choice may, or may not, be a natural solution for the problem.
For example, the “list” command has specific implementation ramifications. Static lists require that the maximum number of items be known beforehand. If the number of items is a static value, then this is the natural representation. The amount of storage needed and used will be static and reliably available.
If however the number of items is not statically known, or the number changes during program execution, then the programmer will need to select a maximum size that is perhaps much higher than the likely average number of items. Thus storage space may be unnecessarily wasted.
Dynamic lists are created at run time. If the total number of items to be stored is not statically known then this may be the ideal implementation. However, by their very nature, dynamic lists may grow at run-time and thus the resources they need are unknown and will cause an error condition should the available memory be exhausted. It might not be possible to prove, prior to execution, that enough space will be available, especially for embedded systems with limited memory capacity.
Dynamic lists rely on pointers to build and maintain the data structure. Depending on the language features, pointers introduce the possibility for hard-to-detect errors, such as dangling references (pointers to objects that no longer exist).
The above “list” example shows the benefits and detriments of both solutions to the simple task of maintaining a list. The key point is that either may be the best solution to the problem given the requirements, whether it is a static number of items to be stored, or not.
If the solution is selected based solely on a single programming language, then the optimum solution for the problem may not be selected, or even considered.
The programming languages discussed here and illustrated in Figure 1 should be considered analogous to a tool box. Each language is a tool to help solve a problem. By comparing the solution that each tool offers, a student can then select amongst these solutions and decide which one is best for the problem at hand. The hammer will be used for the nail and the screw driver for the screw.
This ideal of selecting the best solution to the problem is only available if a student has been exposed to multiple ways of looking at the problem and to multiple ways of programming software code. Students must be given an understanding of a wide variety of languages as well as the different problem area solutions and different methodologies for which they were designed, so that they have all the tools they need to succeed in life after college.
Greg Gicca is director of safety and security product marketing at Adacore . He has over 20 years’ experience in designing and implementing software development tools, and has participated in industry and government groups responsible for defining software quality evaluation standards.