TITLE: Another Advertisement for Smalltalk AUTHOR: Eugene Wallingford DATE: June 10, 2005 3:10 PM DESC: Why don't I program in Smalltalk more often? ----- BODY: Last week, I posted a note on a cool consequence of Smalltalk being written in Smalltalk, the ability to change the compiler to handle new kinds of numeric literals. Here is another neat little feature of Smalltalk: You can quit the interpreter in the middle of executing code, and when you start back up the interpreter will finish executing the code! Consider this snippet of code:
If you execute this piece of code, whether as a method body or as stand-alone code in a workspace, it will execute the first statement -- which saves the image and quits. But in saving the image, you save the state of the execution, which is precisely this point in the code being executed. When you next start up the system, it will resume write where it left off, in this case with the message to start up a web server. How I wish my Java environments did this... This is another one of those things that you want Java, Perl, Python, and Ruby programmers to know about Smalltalk: it isn't just a language; it is a living system of objects. When you program in Smalltalk, you don't think of building a new program from scratch; you think of molding and growing the initial system to meet your needs. This example is from Squeak, the open-source Smalltalk I use when I have the chance to use Smalltalk. I ran across the idea at Blaine Buxton's blog, and he found the idea in a Squeak Swiki entry for running a Squeak image headless. (A "headless image" is one that doesn't come up interactively with a user. That is especially useful for running the system in the background to drive some application, say a web server.) -----
Smalltalk snapshot: true andQuit: true.
... code to execute at next start-up, such as:
PWS serveOnPort: 80 loggingTo: 'log.txt'