View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Daniel King

About Me:

I'm a second year CS major from Lawrenceville, Georgia.
I am primarily interested in 3D graphics, but I am interested in most of CS.
I don't really have much time for hobbies at the moment, but I have found that one of the best ways to waste a little extra time is just to randomly Google some topics.
I am currently a CS 1322 TA.

Discussion 1

Java for Smalltalk Programmers, by Chris Laffra

This article compares the features and uses of the Java and Smalltalk languages. It also makes some comparisons to C++.

How do these languages differ?

One of the largest differences between Java and Smalltalk is typing. Java requires each variable to be declared with a type, while Smalltalk dynamically assigns types. In Smalltalk, a variable that one stored an integer can later be used to store a string, which is impossible with Java.
Smalltalk development is done in an interactive environment. Everything is done by sending messages to the environment. Unlike Smalltalk, Java code must be compiled one class at a time. Changes can not be made to the code while it is running.
Everything is an object in Smalltalk, but Java has some primitive types.
Smalltalk uses blocks to control flow, while java has special keywords to control flow.
Smalltalk has very little syntax, everything is within libraries. Java has much more complex syntax and keywords.

How does that affect people’s programming?

Since Java requires types to be specified, the compiler can perform type checking, whereas Smalltalk will just give a DoesNotUnderstand message when something is wrong. The specified types also help a reader to understand how the variables are used, since naming is not always sufficient. Though, a disadvantage of requiring typing is that it increases the number of keystrokes and time required for development.
The interactive development environment of Smalltalk allows programmers to be very efficient. Changes can be made as the program is running, instead of compiling every time a change is made in Java.
Primitives in Java can cause problems when Collections are needed. The programmer must use a wrapper class in order to store it in the Collection. Whereas in Smalltalk, everything is already an object and can be stored in a Collection without any further action.
Smalltalk was developed for simplicity and fast development, while Java was development to be cross-platform and internet distributed.


Russel Myers' discussion gives some similarities between Smalltalk and Java, and it also gives one or two other differences. Since Smalltalk doesn't support looping, the programmer is somewhat restricted, unlike with Java. Though there must be some substitute to loops in Smalltalk, the ease of loops in Java makes programming more efficient in certain situations. Java has an extensive API, unlike Smalltalk. But, Smalltalk's easy syntax makes up for that limitation. Java and Smalltalk are similar in several ways, so it would be fairly easy to go from one to the other without having to completely re-learn everything. Each language focuses on a different area, and therefore, is better suited for certain projects.

Discussion 2

Part 1:

What are the differences between creational, structural, and behavioral patterns?

Creational patterns handle the creation of objects. They control the creation to prevent complexity in the program. Implementations of this pattern are responsible for instantiating the object with the correct parameters and doing whatever else is required to set up the object. An example of a creational pattern is a factory. Factories are often used to handle the creation of several related objects. The factory creates the specified object and returns it for use elsewhere.

Structural patterns combine objects and their functionalities for a new purpose. They define relationships between multiple objects. An example is the adapter pattern, which provides a consistant interface for several related object. Though these objects may be different in implementation, the interface allows them to be used in the same ways.

Behavioral patterns handle communications between objects. It ties common communication methods together with patterns. This increases flexibility, since one pattern could be useful for several different objects. An example is the iterator pattern. Iterators allow the traversing of a list of objects, while hiding the internal implementation of the list. This allows a standard set of commands to be performed on several types of lists.

Wikipedia - Design Pattern
Using Design Patterns in UML

Part 2:

An interesting creational pattern is lazy initialization. This pattern uses a factory to instantiate an object only when it is required. By not creating an object until it is needed can help save memory and processing time. After an object is created it is stored so that it can be accessed again later without having to reinstantiate.

I am interested in this pattern because it can prevent the waste of memory by storing objects which are not yet needed. It could also be useful if the pattern were extended to remove the object from memory after it is no longer required. Also, intense processes can be postponed until they are really required. It is an interesting alternative to loading everything at once.

One possible use of lazy initialization is the loading of pictures. Since loading many pictures at the same time would require much memory, it is more efficient to simply load the picture when it is first shown. It would also be practical for virtual environments. Only objects that have been within the view need to be loaded. Other objects can be loaded as they come into view.

Wikipedia - Lazy Initialization

Discussion 3

Part 1:

I had a problem with the saving and loading of a project file that had me fearing that I would have to start all over again.

Once I finished everything for Milestone 1, I set up an example presentation and had the required code to set it up in a workspace, along with browsers opened to my class files. So, then I go to save it as a project file. After I click save, nothing seemed to happen, so I decided to try again. Now, a little box pops up saying “Publishing (collecting resources…)” and then disappears. But then, the box comes back. So, I though it was just doing some more saving, but after a minute or so, I had decided that it was not going to finish. I tred to get rid of the box and get back to my project, but there was no way to close it, and I could not even access my project – it was protected by some sort of grid. Not making much progress, I restarted Squeak and saw that a file was saved, so I loaded it. However, that annoying box was still there.

I didn’t feel like fiddling with it at the time, so I just opened up the project file in Wordpad, found my code and copied and pasted it into a new file. This time I made sure not to even think about clicking the save button twice.

However, now that I’ve had time to work with it, I have determined that there is a much simpler solution: simply click anywhere in the workspace and select "Previous Project" - the first thing in the World menu - and voila, the box vanishes and takes the grid with it. Though this is a very simple way to solve the problem, it is not very apparent. I would expect there to be some sort of cancel button, rather than going to the previous project. And, I would think that you couldn't save a saving project anyway.

Here is the box itself - you can click on it and on the grid all you want, but it won't be pushed aside:
Uploaded Image: evil.jpg

Part 2:

I found Andrew Calvin's discussion dealing with event handling particularly useful. He listed out all the events that can be 'caught', which would have really helped me when I was making the button for my M1 timer widget. I had problems getting the button to work, since I didn't know much about event handling in Squeak, and my solution did not work very well. Andrew also gives examples of effects in menus, such as rollover effects, which could be very useful to make a program visually appealing.

I also found Ashley Durham's discussion about the method finder in Squeak useful. I didn't even realize that the Method Finder existed until I read her discussion; I had only used the class browsers to find what I needed for my programs. Now I can save some time searching by using the Method Finder when the Class Browser is not giving me what I need to get something done.

Discussion 4:

Java-to-Smalltalk Guide:

One major difference between Java and Smalltalk is typing. Unlike Java's static typing, Smalltalk uses dynamic typing. In Java, you must declare if something is an int or double or even objects such as ArrayList. However, in Smalltalk you can store whatever you like in any variable. Though this may cause problems with incorrect types, it makes the language more flexible.

Everything in Smalltalk is an object. This means that you can call methods on anything, whereas in Java, primitives such as int, double, and boolean have no methods. Methods are also different in Smalltalk. You call a method by simply putting a space after the object and then the name of the method. In Java, you must put a '.', the method name, and () even if you don't use any parameters. Methods in Smalltalk are really messages, you have an object and you send it a message. The object can also return, just like Java; however, in Smalltalk, '^' is the return keyword, whereas Java uses 'return'. Parameters in Smalltalk are written right after a message ending with a ':'. The colon indicates that it takes a parameter. To take in more than one parameter, the message must be in the form 'message1: param1 message2: param2'. In Java, parameters are within the parantheses, separated by commas.

Order of operations in Smalltalk is also different. Unlike the mathematical order of operations in Java, Smalltalk basically just goes from left to right. Though, parenthesis can be used to give certain operations precedence.

Blocks are something Smalltalk has but Java does not. Blocks in Smalltalk can be used almost like methods; they can take in values, perform some operation, and effectively return the result. A common use of blocks is for the condition of a while loop, and the code to execute each iteration. Though the condition of a while loop is a block, the condition of an if statement is not.

Smalltalk is more uniform than Java; however, it can be difficult to learn Smalltalk because of the lack of an API. You must use browsers and inspectors to learn new objects and methods.

Discussion 5
Categories: Smalltalk blocks, Collection classes, Compare Java and Squeak

Convert the following Java code into Squeak.
Write the average, sum, and multiply methods as blocks in the initialize method of the SpreadSheetHelper class.
Use an OrderedCollection as the integer array.

public class SpreadSheetHelper {

  public static int absoluteValue(int array) {

    if (array < 0) {
      array = negate(array);
    } else {
      array = array;

    return array;


  public static int negate(int array) {

    array = 0 - array;

    return array;


  public static int double(int array) {

    array = 2 * array;

    return array;


  public static int[] performCalculation(int[] array, int choice) {

    int[] returnArray = new int returnArray[array.length].

    if (choice == 0) {
      for (int i = 0; i < array.length; i++) {
        returnArray[i] = absoluteValue(array[i]);
      return array;
    if (choice == 1) {
      for (int i = 0; i < array.length; i++) {
        returnArray[i] = negate(array[i]);
      return array;
    if (choice == 2) {
      for (int i = 0; i < array.length; i++) {
        returnArray[i] = double(array[i]);
      return array;

    return null;



Squeak Code:

Object subclass: #SpreadSheetHelper
	instanceVariableNames: 'average multiply sum'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Final Exam'


  "Insert code here to create the average, multiply, and sum blocks"

performCalculations: array choice: choice

  "Insert code here to perform the chosen action and return the result."



  absoluteValue := [:value |(value  0) ifTrue: [0 - value.] ifFalse: [value.].].

  negate := [:value | 0 - value.].

  double := [:value | 2* value.].

performCalculations: array choice: choice
  returnArray := OrderedCollection new.

  (choice = 0) ifTrue: [array do: [:element | returnArray add: (absoluteValue value: element)]. ^array.].
  (choice = 1) ifTrue: [array do: [:element | returnArray add: (negate value: element)]. ^array.].
  (choice = 3) ifTrue: [array do: [:element | returnArray add: (double value: element)]. ^array.].


Link to this Page