Cmm and Java Compared

Simplicity and Power Through Scripting

 

Visit Nombas Homepage for up-to-date script language technology

 

A comparison of modern languages for the internet and WorldWide Web

Author's note: I wrote this article late in 1995. It is now April 1997. For the most part this information is still accurate although there have been some changes; for example, both languages have been updated, both support more platforms (Cmm evens treats Java as a platform), and the Cmm language has gone from being called ScriptEase to its current merging with JavaScript as the ECMA standard EcmaScript language. For more information about the Java changes in the last 18 months see Author's Update to Java the Illusion.

 
The Java and Cmm languages were each developed to be a secure and portable C-like language for extending safe programming control to everything from personal computers to consumer electronics, from the mainframe to the washing machine. Both development companies, Sun who developed Java and Nombas who developed Cmm, independently designed a language that was portable between all (or most) hardware platforms and operating systems, was safe from the types of bugs (intentional and unintentional) that programmers too often create, and that was familiar to the legions of existing C/C++ programmers.

Both languages attain these goals by creating a C-like interpreted language that protects programmers from the most common problems by automating memory management and removing risk-prone pointer references. Both languages implement run-time interpretation of virtual-machine object codes and also provide run-time verification of these object codes.

But in deciding what changes to make to the C language to meet their goals, these teams followed very different paths. Java started with the C++ class syntax, which is already an extension of C, and extended that language further by adding new Java-specific syntax, keywords, and restrictions. At one point the Java developers decided that C++ would need too much work to meet their goals and so they developed an entirely new language, although it still resembles C and C++. Cmm followed the opposite approach: creating a simplified script-language version of C that removes or automates C's difficult or unnecessary restrictions on syntax, keywords, or data management. The Cmm design goal was always to keep the Cmm language as close to C as possible (but no closer).

Both languages meet the goals of providing portability and restricting potential for errors. Java attains these goals by adding new complexity, restrictions, and classes to a new C++-like language, and creating a complete new safer set of classes and functions, putting the burden of extra work on the programmer. Cmm, on the other hand, achieves these goals by simplifying the C-language and loosening the restriction of that language, while retaining all of the of standard libraries of functions, putting the burden of extra work on the Cmm run-time interpreter (or compiler).

Handling of text strings is one good example of how Java and Cmm differ--an example that illustrates how the different Java and Cmm paths taken for modifying C can lead to very different code. Java strings are handled by one of two newly-created classes: String for constant-length strings and StringBuffer for strings that can be modified. Because these strings are a new type they receive a complete new set of methods for modifying strings, comparing strings, converting strings to arrays, and getting/setting substrings. In Cmm, by contrast, strings are defined exactly as they are in C: as an array of characters. Cmm arrays are just like C arrays, and so all of the string functions that have become standard in C over 25 years are the same functions used in Cmm, but become even easier to use because Cmm arrays are automatically grown and cleaned as needed. These standard and traditional C/C++ string functions would not work in Java because arrays and strings are new and independent data classes. The plus and minus operators, for example, work the same on Cmm string as they do in C, but in Java the plus and minus operators have entirely new meanings for strings.

Similar differences can be shown for handling structures, classes, arrays, lists, and so on. Starting from the same point, the initial design decisions differentiating Java from Cmm have sometimes led to very different paradigms. The following chart summarizes the main points:

Feature

Java

Cmm

robust, secure, portable, C-like language for the internet and WWW

yes

yes

operators (math and logic)

same as C

same as C

control flow

same as C

same as C

number of keywords

50 (30 new keywords plus C keywords
except for "goto")

12 (C keywords without type declarations)

data types

boolean, byte, char, double, float, int, long, short

byte, int (32-bit), float (64-bit)

arrays

special type, requires "new" operator and
limited to allocated size

intrinsic for all data types, no limit on index size or nested depth

array operators

none (use "new" for creation)

same as C (Cmm array math is like C pointer math)

strings

two special classes; all-new Java-specific
functions for comparing and modifying

same as C (byte array using the standard C library of strxxx functions)

structures

not supported; use instead class notation;
inherit at compile-time; static at run-time

full support with C-notation; dynamic run-time creation and extension

garbage collection

automatic (delayed in separate thread)

automatic (real-time as variables go out of scope)

minimal
"Hello, World" program
import browser.Applet;
import awt.Graphics;
class HelloWorld
extends Applet {
public void init() {
resize(150,25);
}
public void
paint(Graphics g) {
g.drawString(
"Hello,World!",
50,25);
}
}
puts("Hello World!")

New concepts and functions for C/C++ programmer introduced in "Hello, World" above

lots and lots

only one P ( main() is now optional )

security

configurable

configurable

remote processing

program-level

program-, function-, or statement-level

current version

1.0 beta

2.1

Year of first commercial product

1996 (estimated)

1993

Size of required executables

~500K (does not include libraries)

~160K (includes libraries)

supported platforms

Unix (Solaris), Windows 95 & NT

Windows & WFWG 3.1x, Windows 95 & NT, OS/2, DOS, DOS-32, Linux, Unix, Netware NLM

Message from 1999:

It has been a long time since the above chart was created. Java and Cmm (now JavaScript) have both come a long. They're now found together in ScriptEase:ISDK/Java, the developer's kit for adding embedded JavaScript into any Java application.