CS102: Language Comparison

Copyright © 1999, Kenneth J. Goldman

Language Comparison

CS101 and CS102 have focused primarily on the creation of software. However, since software is generally created by writing code in some programming language, one important area of computer science is the creation of programming languages themselves. There is not (nor will there ever be) one ultimate programming language. With each new advance in software design, we strive to develop programming languages that provide better support for software developers.

Designing a programming language is a very large undertaking and it involves much more than just a choice of syntax. There are many ( sometime competing) concerns, such as:  

  • What is the programming model and its semantics? (functional, procedural,rule-based,object oriented)
  • Within the model, what are the primitives and how does a developer define new types?
  • How are things composed to build larger units?
  • How does the language map to the underlying hardware?
  • How do language features interact?
  • Etc.
  • Hundreds or thousands of decisions are made in the course of designing a programming language. Each one can have important implications for the way a software developer thinks about how to solve a problem, and also for the efficiency of both the compiler and the executable code.

    A full discussion of programming language deign is beyond the scope of this course (try CS455 (programming languages) and CS431 (compilers)). However, to give you a glance at some of the kinds of descisions language desingers face, we'll take the next two lectures to do a side-by-side comparison of two very similar programming languages: Java and C++. (This will also be useful as an introduction to C++).  

    Important Similarities of Java and C++

    Important Differences of Java and C++

  • C++ does not have a garbage-collected heap - you must destroy objects yourself when you finish with them
  • C++ objects can be allocated either on the stack on in the heap (In Java, all objects are on the heap)
  • C++ has support for:
  • parameratized types (templates)
  • operator overloading
  • multiple inheritance
  • C++ has pointers that can refer to arbitrary memory lacations, and you can perform arithmetic on them (to walk through the contents of an array, for example)
  • C++ is not type safe
  • C++ allows call-by-value AND call by reference (Java has only call-by-value)
  • Each C++ class has a separate header file that defines its interface
  • C++ does not have built-in support for threads, security,graphics, etc --- instead you choose to include separate class libraries with the support you want
  • C++ does not have a class Object, so instead of a tree for the class hierarchy, there is a forest
  • C++ provides very little type information at run-time
  • C++ provides fewer checks at run-time (array bounds,class cast, null pointers, etc are not cheked, and may result in strange errors)
  • C++ programs generally run faster than Java programs
  • Summary

    In general C++ is a more complicated language to use because it has some additional features, fewer safegaurds, and no garbage collection. Hoever, once you know one object oriented language, (like Java) its not too hard to learn C++.

    In class, we looked at some C++ code and made specific comparisons of some of the language features.