smalltalksqueak

Is there a way to define classes and their members and functions by syntax rather than going through the GUI (browser menu)?


I am trying my hands at Smalltalk and downloaded Squeak as my first attempt. It seems that the "Workspace" in Squeak is where you run your code. So far so good for a "HelloWorld" example. Then I wanted to make some classes and I realized a problem: In the tutorials I've seen so far, there were only examples of adding classes through the browser menu.

Thus my question: Is there a way to define classes and their members and functions by syntax, that is, textual, as part of your script, rather than going through the the GUI?

If there is no alternative to going through the GUI, this is going to be a pain to maintain my projects. I am used to languages like C/C++, Python, Javascript and I like the fact that all of my assets are in text files. One advantage of this is that if I want to run my projects on another system, all I have to do is install the compiler/interpreter for the project's language and I can just compile and/or run from the shell. Another advantage of your assets being text files, is that it works well with Git.

I don't particularly look forward to the scenario where I have some large Smalltalk projects and want to transfer it to a new computer, that I need to manually re-enter everything through the GUI.


Solution

  • Smalltalk developers will always use the code browser tools to develop software in Smalltalk. That is because it is a live programming environment: development and execution of your code are much more blended than any other language. It is, for example, very common to change and add code from within the debugger (i.e. while the program is running).
    But that does not mean that your code cannot be easily shared, stored and versioned. Just take a look at all the Pharo Contributions projects on Github: did you really assume developers need to copy/paste the code into a system? There are several ways to save and load code to (and from) external (text) files. Depending on the Smalltalk implementation (Squeak, Pharo, VAST, GemStone, Cuis, ...), there are also several ways to store a project in a version-control system.

    You can file-out and file-in all of your code to a textual format. This can be done for individual methods and classes as well as entire packages. In Pharo, for example, when right-clicking on a package, class or method, you will find the 'file out' menu item in the context menu. Once filed-out, you can simply drop that file on another Pharo image to load the code, or you can use the built-in File Browser from the world menu to select the file.

    However, file-in and file-out will be rarely used to actually store and version code. Instead, Pharo's Iceberg tool is how you load and store projects in Git. For that, a textual format called 'Tonel' is used to export Smalltalk code in human readable format to Git. See the excellent Pharo by Example book for some introductory chapter on how to use Iceberg. In Squeak, code is stored and versioned using the Monticello tool. In VAST, versioning is done using an entirely different version system called 'Envy', which is not text-file based and blends more into the Smalltalk development tools.

    I recommend you give Pharo a try and save your code to Github using Iceberg.