An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

ColdFusion and Smalltalk

July 25, 2006 · 4 Comments

With all the talk on various blogs about the Java-like OO features people seem to want to add to ColdFusion, I thought it might be instructive for folks to learn a little more about Smalltalk - a language with which I think ColdFusion actually has more in common than Java. Here's a good article on the pros of Smalltalk: Have You Considered Smalltalk? by Jeffry D. Panici. In particular - in light of calls for constructors and interfaces in ColdFusion - I think the following quote from the above article is very telling:
An interesting difference between Smalltalk and Java/C++ is that the class side is responsible for instantiating the instance side of a class. Therefore Smalltalk has no official constructor syntax like Java or C++. The Named Constructor Idiom is the closest equivalent in the Java and C++ world to the way a Smalltalk programmer would instantiate a class instance. In practice, Smalltalk's classes have so few restrictions on them that they're much more powerful and robust than their Java or C++ counterparts. Since Smalltalk is dynamically typed it is easy to treat the class hierarchy as a kind of super-schema that can be modified in real-time. While most Smalltalk's don't directly support multiple inheritance, many do support adding the functionality if desired. Java does not support multiple implementation inheritance, and multiple interface inheritance has many drawbacks. It's important to remember that there is no arbitrary limitation on implementation inheritance within Smalltalk like there is in Java. If you want to change String or inherit from it, you're more than welcome.
Two things here probably need some clarification: 1. Smalltalk does not have constructors in the Java/C++ sense. Instead, each Smalltalk class (the type of an object - actually an instance of a metaclass object, similar to Java's Class class) understands the message code which returns a new instance of the class. You typically have named methods that return new instances appropriately initialized. The closest equivalent in Java/C++ is a static factory method (with the actual default constructor being private or protected). 2. Smalltalk supports adding functionality at runtime. This is just like ColdFusion's CFCs: you can add (and delete) methods after creating the instance. Methods (functions) are first class objects you can pass around and assign to variables, shuffling them between CFC instances. Read over the quoted section again: "[Smalltalk's] classes have so few restrictions on them that they're much more powerful and robust than their Java or C++ counterparts." The same can be said of ColdFusion Components - but you have to think outside the Java box to realize that.

Tags: coldfusion

4 responses so far ↓

  • 1 Sami Hoda // Jul 25, 2006 at 8:28 PM

    SmallTalk was the first official language I learned, and there were definitely a certain charm to it.
  • 2 Mike Kelp // Jul 26, 2006 at 6:16 AM

    What I think is so confusing about this whole argument is that anytime someone says "I want interfaces" everybody thinks they should insert "Java" into that. SmallTalk and Python seem to have a fairly similar interface scheme, but the concept is there and does fit the definition, though with greater flexibility than Java as it seems.

    Personally, I want what interfaces offer us in our ColdFusion objects. I want interfaces by their definition, not by their use in another language. ColdFusion could benefit from the concept of interfaces and as I have said in a blog post before, make them better. That's what coldfusion does. Take CFCs for instance. We got a nice object format that's clean, dynamic, and a sweet way to deal with webservices. No it is not a Java class, but a good programming concept was applied and improved. I don't think a single person complained about that.

    One thing I like about interfaces is that they can make a large set of objects easy to understand and implement the capabilities of in your own code. If we get compile time benefits from it similar to Java, great, if not, we might get some of those nice dynamic interface benefits in the form of implementing interfaces at runtime. Either way, my interest to make my objects more consistent and easier to drop in to my own code has been benefitted. I am confident in the ColdFusion team's ability to take the things I ask for to a new level, which is why I ask for it and expect it.

    Thanks for the good discussion and SmallTalk education as I am only as familiar with it as my reading has taken me. Anyway, I'll see you at the static functions bruhaha. :-)
  • 3 Paul Dale // Aug 14, 2006 at 5:11 PM

    <quote>
    This is just like ColdFusion's CFCs: you can add (and delete) methods after creating the instance. Methods (functions) are first class objects you can pass around and assign to variables, shuffling them between CFC instances.
    </quote>

    Hi I've been coding cfc's since way back and this is the first I've heard of this capability - would you care to clarify or point to a reference where I can check this out? Regards, Paul.
  • 4 Sean Corfield // Aug 14, 2006 at 10:01 PM

    Paul, you can just assign a method from one CFC instance to another or even just assign a regular ol' UDF into a CFC.

    myObj = createObject("component","SomeObject");

    myObj.newMethod = someUDF;

    myObj.newMethod();

Leave a Comment

Leave this field empty: