Skip to main content
Engineering LibreTexts

3.10: Saving and Sharing Pharo Code

  • Page ID
    40056
    \( \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}}\)

    Now that you have Lights Out working, you probably want to save it somewhere so that you can archive it and share it with your friends. Of course, you can save your whole Pharo image, and show off your first program by running it, but your friends probably have their own code in their images, and don’t want to give that up to use your image. What you need is a way of getting source code out of your Pharo image so that other programmers can bring it into theirs.

    Note

    We’ll be discussing the various ways to save and share code in a future chapter, Chapter : Sharing Code and Source Control. For now, here is an overview of some of the available methods.

    Saving plain code

    The simplest way of doing this is by ”filing out” the code. The right-click menu in the Package pane will give you the option to File Out the whole of package PBE-LightsOut. The resulting file is more or less human readable, but is really intended for computers, not humans. You can email this file to your friends, and they can file it into their own Pharo images using the file list browser.

    Right-click on the PBE-LightsOut package and file out the contents (see Figure \(\PageIndex{1}\)). You should now find a file named PBE-LightsOut.st in the same folder on disk where your image is saved. Have a look at this file with a text editor.

    File Out our PBE-LightsOut.
    Figure \(\PageIndex{1}\): File Out our PBE-LightsOut.

    Open a fresh Pharo image and use the File Browser tool (Tools --> File Browser) to file in the PBE-LightsOut.st fileout (see Figure \(\PageIndex{2}\)) and fileIn. Verify that the game now works in the new image.

    Import your code with the file browser.
    Figure \(\PageIndex{2}\): Import your code with the file browser.

    Monticello packages

    Although fileouts are a convenient way of making a snapshot of the code you have written, they are definitively ”old school”. Just as most open-source projects find it much more convenient to maintain their code in a repository using SVN or Git, so Pharo programmers find it more convenient to manage their code using Monticello packages. These packages are represented as files with names ending in .mcz. They are actually zip-compressed bundles that contain the complete code of your package.

    Using the Monticello package browser, you can save packages to repositories on various types of server, including FTP and HTTP servers. You can also just write the packages to a repository in a local file system directory. A copy of your package is also always cached on your local disk in the package-cache folder. Monticello lets you save multiple versions of your program, merge versions, go back to an old version, and browse the differences between versions. In fact, Monticello is a distributed revision control system. This means it allows developers to save their work on different places, not on a single repository as it is the case with CVS or Subversion.

    You can also send a .mcz file by email. The recipient will have to place it in her package-cache folder; she will then be able to use Monticello to browse and load it.

    Monticello Browser

    Open the Monticello browser from the World menu (see Figure \(\PageIndex{3}\)).

    Monticello browser.
    Figure \(\PageIndex{3}\): Monticello browser. The package PBE-LightsOut is not saved yet.

    In the right-hand pane of the browser is a list of Monticello repositories, which will include all of the repositories from which code has been loaded into the image that you are using. The top list item is a local directory called the package-cache. It caches copies of the packages that you have loaded or published over the network. This local cache is really handy because it lets you keep your own local history. It also allows you to work in places where you do not have internet access, or where access is slow enough that you do not want to save to a remote repository very frequently.

    Saving and loading code with Monticello

    On the left-hand side of the Monticello browser is a list of packages that have a version loaded into the image. Packages that have been modified since they were loaded are marked with an asterisk. (These are sometimes referred to as dirty packages.) If you select a package, the list of repositories is restricted to just those repositories that contain a copy of the selected package.

    Add the PBE-LightsOut package to your Monticello browser using the + Package button and type PBE-LightsOut.

    SmalltalkHub: a Github for Pharo

    We think that the best way to save your code and share it is to create an account for your project in SmalltalkHub. SmalltalkHub is like GitHub: it is a web front-end to a HTTP Monticello server that lets you manage your projects. There is a public server at http://www.smalltalkhub.com/.

    To be able to use SmalltalkHub you will need an account. Open the site in your browser. Then, click on the Join link and follow the instructions to create a new account. Finally, login to your account. Click on the + New project to create a new project. Fill in the information requested and click Register project button. You will be sent to your profile page, on the right side you will see the list of your projects and projects you watch by other coders. Click on the project you just created.

    Under Monticello registration title label you will see a box containing a smalltalk message similar to

    MCHttpRepository
        location: 'http://www.smalltalkhub.com/mc/UserName/ProjectName/main'
        user: 'YourName'
        password: 'Optional_Password'
    

    Copy the contents and go back to Pharo. Once your project has been created on SmalltalkHub, you have to tell your Pharo system to use it. With the PBE-LightsOut package selected, click the +Repository button in the Monticello browser. You will see a list of the different Repository types that are available. To add a SmalltalkHub repository select smalltalkhub.com. You will be presented with a dialog in which you can provide the necessary information about the server. You should paste the code snippet you have copied from SmalltalkHub (see Figure \(\PageIndex{4}\)). This message tells Monticello where to find your project online. You can also provide your user name and password. If you do not, then Pharo will ask for them each time you try to save into your online repository at SmalltalkHub.

    Create your first repository on SmalltalkHub.
    Figure \(\PageIndex{4}\): Create your first repository on SmalltalkHub.

    Once you have accepted, your new repository should be listed on the right-hand side of the Monticello browser. Click on the Save button to save a first version of your Lights Out game on SmalltalkHub. Don’t forget to put a comment so that you, or others, will have an idea of what your commit contains (see Figure \(\PageIndex{5}\)).

    Do your first commit.
    Figure \(\PageIndex{5}\): Do your first commit.

    To load a package into your image, open Monticello , select the repository where the package is located and click open button. It will open a new window with two columns, left one is the Package to be loaded, the right one is the version of the package to be loaded. Select the Package and the version you want to load and click the load button.

    Open the PBE-LightsOut repository you have just saved. You should see the package you just saved.

    Monticello has many more capabilities, which will be discussed in depth in Chapter : Sharing Code and Source Control.

    About Git. If you are already familiar with Git and Github there are several solutions to manage your projects with Git. This blog posts provides a summary: http://blog.yuriy.tymch.uk/2015/07/pharo-and-github-versioning-revision-2.html#! There is a chapter in preparation on about how to use Git with Pharo. Request it on the Pharo mailing-list.


    This page titled 3.10: Saving and Sharing Pharo 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.