Skip to main content
Engineering LibreTexts

6.10: In Smalltalk, You Can’t Lose Code

  • Page ID
    38009
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)

    It is quite possible to crash Squeak: as an experimental system, Squeak lets you change anything, including things that are vital to make Squeak work!

    \(\bigstar\) To maliciously crash Squeak, try Object become: nil.

    The good news is that you need never lose any work, even if you crash and go back to the last saved version of your image, which might be hours old. This is because all of the code that you executed is saved in the .changes file. All of it! This includes one liners that you evaluate in a workspace, as well as code that you add to a class while programming.

    So here are the instructions on how to get your code back. There is no need to read this until you need it. However, when you do need it, you’ll find it here waiting for you.

    In the worst case, you can use a text editor on the .changes file, but since it is many megabytes in size, this can be slow and is not recommended. Squeak offers you better ways.

    How to get your code back

    Restart Squeak from the most recent snapshot, and select World ⊳ help ⊳ useful expressions. This will open a workspace full of useful expressions. The first three,

    Smalltalk recover: 10000.
    ChangeList browseRecentLog.
    ChangeList browseRecent: 2000.
    

    are most useful for recovery.

    If you execute ChangeList browseRecentLog, you will be given the opportunity to decide how far back in history you wish to browse. Normally, it’s sufficient to browse changes as far back as the last snapshot. (You can get much the same effect by editing ChangeList browseRecent: 2000 so that the number 2000 becomes something else, using trial and error.)

    One you have a recent changes browser, showing, say, changes back as far as your last snapshot, you will have a list of everything that you have done to Squeak during that time. You can delete items from this list using the yellow button menu. When you are satisfied, you can file-in what is left, thus incorporating the changes into your new image. It’s a good idea to start a new change set, using the ordinary change set browser, before you do the file in, so that all of your recovered code will be in a new change set. You can then file out this change set.

    One useful thing to do in the recent changes browser is to remove doIts. Usually, you won’t want to file in (and thus re-execute) doIts. However, there is an exception. Creating a class shows up as a doIt. Before you can file in the methods for a class, the class must exist. So, if you have created any new classes, first file-in the class creation doIts, then remove doIts and file in the methods.

    When I am finished with the recovery, I like to file out my new change set, quit Squeak without saving the image, restart, and make sure that the new change set files back in cleanly.


    This page titled 6.10: In Smalltalk, You Can’t Lose Code is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Andrew P. Black, Stéphane Ducasse, Oscar Nierstrasz, Damien Pollet via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.