The Smalltalk Programming Language: A Comparison with Java

The Smalltalk Programming Language: A Comparison with Java Colin Whitehouse 5/24/04 Smalltalk came around long before Java did, and even long befor...
Author: Ross Hunt
15 downloads 4 Views 67KB Size
The Smalltalk Programming Language: A Comparison with Java

Colin Whitehouse 5/24/04

Smalltalk came around long before Java did, and even long before Java's immediate ancestors. Alan Kay, Dan Ingalls, Ted Kaehler, Adele Goldberg, and others invented Smalltalk at the Xerox Palo Alto Research Center (PARC) during the 1970’s. Some new ideas that Smalltalk brought to the programming world was being fully Object Oriented, everything in Smalltalk is an object from strings, to integers and even memory are all represented as objects. Smalltalk also helped greatly with the development of Graphical User Interfaces (GUI’s). Smalltalk has features such as garbage collection, and even has an Intergraded Development Environment (IDE) that is open source and available for modifications. However, a strange feature that Smalltalk doesn’t contain is basic built-in constructs such as for, while, and if-then-else, etc. However Smalltalk can get around this “setback” because everything is an object. For example sending an ifTrue message to a Boolean object makes decisions in the Smalltalk language, and then passes a fragment of code to execute of the Boolean is true. Java was invented by James Gosling and his team at Sun Microsystems. It was first developed in 1991, and was intended to be used to program home appliances such as toasters and TV’s. In 1994, Gosling and his team realized that Java would be ideal for developing Internet applications. Officially Java was announced on May 23, 1995 at the SunWorld Expo, soon many Internet companies such as Netscape took on Java and made their browsers Java compatible. Java has been a successful language for a few reasons, first from when it was released it has always had a IDE which was put out by Sun Microsystems, second it ran secure code on the clients machine therefore disallowing any type of virus writing to be done in Java, and thirdly with a Java Virtual Machine, Java can be run on any platform. The remainder of the paper will be split into twelve sections to help classify the similarities and differences between Smalltalk and Java. The twelve sections will be Efficiency, Simplicity, Orthogonality, Definiteness, Reliability, Expressivity, Abstraction facilities, Portability, Tools availability, Major Application Areas, Extent of current use, and Reverse Engineering. Efficiency: Since Java and Smalltalk are both languages, which get interpreted by virtual machines their speed is greatly affected, compared to compiled languages such as C and C++. However, this performance hit does have some pros to it, such as a being able to run programs cross platform very easily as long as the operating system has the languages virtual machine. This cross platform capability is something that compiled languages don’t have. Simplicity:

Java and Smalltalk are both languages where it is easy to understand written code. They both don’t have constructs that are advanced, hard to understand or could have multiple meanings. Neither have major redundant features, which can cause a maintenance programmer to become confused if the original programmer had used multiple ways to solve problems within the program. Neither languages use operator overloads such as in C/C++ so there is no need for the programmer to look around for multiple uses for the same function, which can become very confusing, when maintaining a large and complex program. Smalltalk’s delimiters and syntax are simple and straight forward, since Java came after Smalltalk, and even borrowed some ideas from Smalltalk, it realized that this was an important feature, which was kept in mind during it’s development. Smalltalk also has great writability since it pioneered the idea that programming could be done with nouns which are objects and verbs which are messages. This made programming simple since it is very similar to spoken language. (Heller, 2002) Since Java’s variables need to be type declared, I feel that this can affect the writability of Java because you need to always keep in mind what the type declarations for each variable are throughout the program. If you make a mistake doing this, it can lead to errors and warnings at compile time. Java’s type checking during compile time is a great way to eliminate variable and expression errors during runtime. Although even in languages such as Smalltalk that aren’t type declared you should still always keep track of what your hold in each variable at all times since it could lead to errors, and data loss for example if you divide with integers. One feature in both Java and Smalltalk that add complexity is multiplicity. For example in both languages there are multiple ways to increment an integer such as var = var + 1, var += 1, var++ and ++var. All four of the basic statements all have the basic same meaning. Although this is simple, it does add complexity in the larger picture. Orthogonality: Since Java and Smalltalk are both object-oriented programming languages they each have the ability to return data structures from functions, which allows programmers to make every part of each language meaningful. Java has all of the basic control statements such as while loops and for loops, which are very common in most of today’s programming languages. All of these controls statements help programmers write structured code, which is easy to understand. However, Smalltalk doesn’t use control statements such as for loops and while loops; instead, since everything in Smalltalk is an object, all the programmer has to do is send an ifTrue message to a Boolean object, which makes decisions in the Smalltalk language, and then passes a portion of code to execute if the Boolean is true.

Definiteness: Java and Smalltalk are both very predictable languages; they do not allow user functions such as operator overloading. This in turn makes the language more predictable as well as giving it better readability. By not allowing complex overloading, it can make the maintenance programmer’s job much easier, because what is stated is what it means, the maintenance programmer doesn’t have to look around the whole program to see if the original programmer had overloaded an operator to give it another meaning somewhere else. Reliability: Java is a reliable language; it offers the programmer many features, which can eliminate runtime errors. Java provides automatic garbage collection, and strong type checking during compile time, which will pick up on errors and allow the programmer to fix them before run time. Smalltalk is a fairly reliable language; it provides helpful items such as automated garbage collection, which can help prevent many run-time errors. However the language doesn’t support strong type checking since in Smalltalk is an untyped language. All of Smalltalk’s variables are never declared to have a certain type, nor do they acquire a type once they have a certain kind of data stored in them, however Smalltalk does keep track of the type of data that is being stored in the variables using internal tags. (Heller, 2002) Expressivity: Smalltalk and Java both have built in libraries with many functions that allow programmers to not have to “reinvent the wheel” when they are programming. By allowing programmers to used predefined libraries of functions it allows them to be more productive as they can reuse code instead of having to write basic functions over and over again. Abstraction Facilities: Both Smalltalk and Java allow many forms of abstraction from recursion to polymorphism and encapsulation. Abstraction features are important in programming languages because they are used to reduce the complexity of a program. Reducing complexity is always a good idea because if something works well and it is simple then the chances of it “breaking” are very unlikely plus it makes the software easier to maintain and update.

Portability: Java is a very portable language; it can run on virtually any operating system, given that that operating system has a Java Virtual Machine. The reason that Java is so portable is because when you compile a Java program it compiles the source file to bytecode, which then gets processed by the virtual machine to the machine code of that operating system. Byte-code isn’t machine language for a computer however; it is very similar and very easy for the virtual machine to translate into machine language. Therefore, you can take the same byte-code file and run it on a virtual machine for say a Windows operating system, a Mac operating system or say even a Linux operating system and get the same results from the program. Smalltalk is also just as portable as Java is. Smalltalk uses a virtual machine as well. However, the main difference between Smalltalk and Java portability is only in terms used, in Java the file that the virtual machine reads is called the “byte-code” file and in Smalltalk it is called the “image” file. Tools Availability: When both Java and Smalltalk were introduced they already had an Intergraded Development Environment (IDE). This is one reason that both of the languages have done well. An IDE is an major part of a programming language and without one it is very hard for developers to develop with that language, and if it is hard for developers then most likely they won’t go out of their way to program in that language. Another plus about both Java’s and Smalltalk’s IDE’s that they were free, and supported debugging and other important features that programmers tend to enjoy as it can make their jobs easier. Extent of Current Use and Application Areas: Java is currently being used to program many applications that need cross platform compatibility. It is used in applications from e-mail clients, administration tools, to web browsers. Another feature that Java has is the ability to program Java applets, which care small programs that run in web browsers or applet viewers. Applets are widely in use on the Internet from things such as games to helping build dynamic web content. The use of Smalltalk has declined over the years, however it is still being used today in some areas such as the countries phone system, batch programs for large mainframes, and oscilloscopes. Smalltalk has also spread into some other “flavors” such as Dolphin Smalltalk and Squeak Smalltalk. Dolphin Smalltalk is a “fully featured rapid software development system for PC based Microsoft Windows applications. It is targeted at Visual Basic/C++/Java

developers who wish to adopt a pure approach to object-oriented programming. Dolphin Smalltalk takes advantages of Windows features such as Win32 APIs that can be accessed from within the Smalltalk environment. As a result Dolphin features are fully featured, yet fast to market and easy to maintain.” (http://www.object-arts.com) Squeak Smalltalk is an implementation of Smalltalk-80, with its virtual machine written entirely in Smalltalk, which makes it easy for programmers to debug, analyze and change. Squeak Smalltalk can also handle real-time sound and music synthesis, antialiased image rotation and scaling, a garbage collector for 32-bit direct pointers among other improvements. (http://www.squeak.org/) Reverse Engineering: Once again both Java and Smalltalk are very similar in this department as well. Since they are both interpreted languages they have their source code compiled into bytecode, which is then interpreted by a virtual machine. To the human eye the byte-code is unreadable, it is code that the virtual machine understands and converts to machine language. However, there are tools for both languages that allow people to reverse engineer the byte-code back a source code file that they can read and edit. The program commonly used for reverse engineering Java is called Mocha. It is freely distributed and available for anyone to download and use, it has also been incorporated into new versions of Borland’s Jbuilder. There is also a tool that can be used to decompile Smalltalk image files called CompiledCodeInspector. Although you can reverse engineer these languages the outcome won’t be perfect to the original however, it will be close enough for a programmer to understand how it works and edit it to their liking. Conclusion: As you can see both Smalltalk and Java are very similar in many ways. They are both object-oriented, have many useful functions like garbage collection and are also both interpreted languages, which is very helpful for portability. They both can be used today for many applications, however it all depends on what kind of application you will be writing before you choose what language you are going to use. I would recommend using Java over Smalltalk currently for most applications since it is a new language, it is more up to date, and is better suited for the Internet with Java’s use of applets. However, Smalltalk is still used in a lot of areas like the Phone Company, older mainframe computers, and oscilloscopes. As they say if it isn’t broken don’t fix it, which is still why Smalltalk is relied in these areas, because it works, so why change it. As a programmer no matter what you are doing, you should never assume you should use a certain language over another, you should always think about what your application will do and what it requires from speed, to operating system portability before you decide what you want to program it in.

Bibliography: Books: Savitch, Walter Java: An Introduction to Computer Science and Programming Pearson Education, 2004 Sebesta, Robert Concepts of Programming Languages Pearson Education, 2004 Budd, Timothy A Little Smalltalk Addison-Wesley, April 1987 LaLonde, Wilf Inside Smalltalk Prentice-Hall, 1990 Hopkins, Trevor and Horan, Bernard Smalltalk: An Introduction to Application Development using Visualworks Pearson Education, 1995 Pinson, Lewis and Winer, Richard An Introduction to Object-Oriented Programming and Smalltalk Addison-Wesley, 1988 Hunt, John Smalltalk and Object Orientation Springer Verlag Publishing, 1997 Lewis, Simon The Art and Science of Smalltalk Prentice-Hall, 1995 Shafer, Dan and Ritz, Dean Practical Smalltalk Springer Verlag Publishing, July 1991 Articles: Heller, Martin. “Untitled” Byte.com 10/7/2002 Burbeck, S.L. “Real-Time Complexity Metrics for Smalltalk Methods” IBM Systems Journal 1996, Issue 2 Levin, Rich. “Not Just Making Smalltalk” InformationWeek 5/27/1996 Issue 581 Websites: Java and Smalltalk Syntax Compared http://www.chimu.com/publications/JavaSmalltalkSyntax.html The Smalltalk Programming Language http://en.wikipedia.org/wiki/Smalltalk_programming_language The Java Programming Language http://en.wikipedia.org/wiki/Java_programming_language Dolphin Smalltalk

http://www.object-arts.com/Home.htm Squeak Smalltalk http://www.squeak.org/ A comparison between BETA, C++, Eiffel, Java, Object Pascal, Ruby and Smalltalk By Michael Neumann, 7/21/2000 http://www.ntecs.de/old-hp/s-direktnet/lang_cmp.en.htm Smalltalk: a Reflective Language By Fred Rivard http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/rivard/rivard.html

Suggest Documents