Skip to main content
Engineering LibreTexts

8.4: In Pharo, You Can’t Lose Code

  • Page ID
    39615
    \( \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}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

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

    The good news is that you will 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. This excludes Playground snippets , those are stored inside /pharo-local/play-chace and they can be searched using Spotter (the results are displayed under Playground-cached pages section).

    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. Pharo offers you better ways.

    How to get your code back

    Restart Pharo from the most recent snapshot, and select World > Tools... > Recover lost changes.

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

    This will give you 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.)

    Once 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 Pharo during that time. You can delete items from this list using the right-click 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 Pharo without saving the image, restart, and make sure that the new change set files back in cleanly.


    This page titled 8.4: In Pharo, You Can’t Lose Code is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.