Pharo Wiki

repository·master·Indexed 42 days ago

https://github.com/pharo-open-documentation/pharo-wiki

Comprehensive documentation for the Pharo programming language and development environment. Covers beginner tutorials, language internals (Traits, Pragmas), tooling (Playground, Inspector), and infrastructure (Baselines, CI/CD). Includes guides on data exchange using STONJSON, NeoJSON, and NeoCSV, as well as the OpenSmalltalk Virtual Machine.

Tokens
57.8K
Snippets
196
Records
273
Agent score
51%

What's inside Pharo

  1. Overview of the Pharo Wiki

    master
    The Pharo wiki is a central documentation hub for the Pharo programming language and development environment. It provides resources for beginners, general infrastructure guidance, language specifics, tooling usage, and information on Pharo projects and the OpenSmalltalk Virtual Machine. Developers can use this wiki to learn how to set up projects, manage dependencies via baselines, use Pharo's built-in tools (like the Playground or Inspector), and understand language features like Traits and Pragmas.
  2. Choose a Pharo source code export format

    master

    Pharo stores source code in memory, which makes long-term management and VCS (like Git) collaboration difficult. To save code in readable files, you must choose an export format.

    Comparison Summary

    FeatureTonel (Recommended)FileTree metadata lessFileTree metadata full
    Best forNew projects, Windows users, Iceberg usersMethod-level historyLegacy/Monticello use
    GranularityOne file per ClassOne file per MethodOne file per Method
    Windows Support✅ Excellent
    Merge Ease✅ Easy
    Space Efficiency✅ High
    Iceberg Support✅ Yes
    Monticello Support✅ Yes✅ Yes✅ Yes

    Recommendation: Use Tonel for new projects, especially if you use Iceberg or work on Windows. Use FileTree metadata less if you specifically need to browse the history of individual methods easily.

  3. Discover Pharo community external resources

    master

    The Pharo community maintains various external blogs and resources covering specific topics such as the Pharo Virtual Machine, Moose, AI/Machine Learning, and general Pharo development. Use these links to find specialized knowledge and community discussions outside of the official wiki.

    | Topic | Resource |
    | :--- | :--- |
    | Pharo General | [astares.blogspot.com](https://astares.blogspot.com), [blog.sebastiansastre.co](https://blog.sebastiansastre.co), [endormitoire.wordpress.com](https://endormitoire.wordpress.com/2016/10/03/freewill-in-progress-4/), [masteringobjects.wordpress.com](https://masteringobjects.wordpress.com), [medium.com/concerning-pharo](https://medium.com/concerning-pharo), [medium.com/@juliendelplanque](https://medium.com/@juliendelplanque), [80738163270632.blogspot.com](https://80738163270632.blogspot.com/) |
    | Pharo VM / OpenSmalltalk-VM | [clementbera.wordpress.com](https://clementbera.wordpress.com), [mirandabanda.org/cogblog/](http://www.mirandabanda.org/cogblog/) |
    | Moose & Pharo | [fuhrmanator.github.io](https://fuhrmanator.github.io) |
    | AI & Machine Learning | [medium.com/@i.oleks](https://medium.com/@i.oleks) |
    | Caffeine (JS VM) & Smalltalk | [thiscontext.com](https://thiscontext.com) |
  4. Keep a collection sorted using SortedCollection

    master

    If you need a collection that remains sorted as new elements are added, use SortedCollection. Unlike standard collections, SortedCollection automatically maintains order upon insertion.

    Warning: Use SortedCollection only when necessary, as it can impact performance during addition and removal operations compared to standard collections.

    Ways to create a SortedCollection:

    1. Transform an existing collection using #asSortedCollection or #asSortedCollection:.
    2. Instantiate directly using SortedCollection sortUsing:, SortedCollection sortBlock:, or (in Pharo 8+) SortedCollection sortUsing:.

    Note: In Pharo 8 and later, #sortUsing: is the preferred method for configuring the sort logic.

    "Transforming an existing collection"
    (#(1 2 4 7 3 6 4) asSortedCollection: #yourself ascending)
        add: 2;
        yourself "a SortedCollection(1 2 2 3 4 4 6 7)"
    
    "Direct instantiation with a sort block"
    (SortedCollection sortBlock: [ :a :b | a < b ])
        addAll: #(1 2 4 7 3 6 4);
        yourself "a SortedCollection(1 2 3 4 4 6 7)"
  5. Follow the wiki entry structure and conventions

    master

    When creating or editing entries, follow these formatting conventions:

    • External Projects: Include small examples, comparisons between projects, and links to official documentation/repositories. If official documentation is missing, the wiki can provide it.
    • Table of Contents: Long entries should start with a table of contents (using a tool like markdown-toc is recommended).
    • References: Place links to external or decentralized documentation in a See also section at the end of the entry.
    • Smalltalk Code:
      • Use tabulation for indentation.
      • Use the following syntax for code highlighting:
     Code
  6. Handle stream positioning and encoding errors

    master

    In Pharo 7, the #position: message operates at the binary level, not the character level.

    If you attempt to set the position into the middle of a multi-byte UTF-8 character, you will encounter a ZnInvalidUTF8: Illegal leading byte for utf-8 encoding error.

    Best Practice: To avoid encoding errors when seeking, read the file sequentially from the beginning or use character-based navigation (e.g., using #next) rather than jumping to arbitrary byte offsets.

    "Safe way to navigate: read sequentially"  
    '1.txt' asFileReference readStreamDo: [ :stream |
        3 timesRepeat: [ stream next ].
        stream upToEnd ].
  7. Understand Traits for behavior composition

    master

    Traits are pure units of behavior that can be composed to form classes or other traits.

    Unlike multiple or mixin inheritance, trait composition gives the composer full control over how behaviors are combined. This provides a mechanism for high code reuse without the typical drawbacks of multiple inheritance.

  8. Declare a launcher for external scripts

    master

    A launcher is a special type of setting node that displays a label but no input field. Instead, it integrates a Launch button into the Settings Browser. Clicking this button executes an associated script or external tool. This is useful for launching external configuration tools or system setup scripts.

    "Note: The specific builder method for launchers is mentioned as 'launcher:' in the text"
    (aBuilder launcher: #updateFromSystem)
    	label: 'Update fonts from system' translated.
  9. Use the Meta tab to explore class hierarchy and methods

    master

    The Meta tab provides a way to explore the relationship between an object and its class definition:

    • Left Pane: Displays the class hierarchy of the current object's class.
    • Right Pane: Displays the methods available. Clicking a parent class in the hierarchy updates the right pane to show methods implemented in that specific class.
    • Bottom Area: Selecting a method displays its source code.
  10. Use ProportionalLayout for responsive submorph sizing

    master

    A ProportionalLayout allows submorphs to resize proportionally when the container morph changes size. This is achieved by assigning a LayoutFrame to a submorph, where the frame represents a percentage of the parent morph's dimensions.

    To implement this:

    1. Set the container's layoutPolicy: to ProportionalLayout new.
    2. Define a frame using asLayoutFrame with coordinates ranging from 0 to 1 (e.g., 0 @ 0 corner: 1 @ 1 represents 100% coverage).
    3. Add the submorph using addMorph:fullFrame:.
    |frame sub|
    m1 := SystemWindow new.
    m1 layoutPolicy: ProportionalLayout new.
    frame := (0 @ 0 corner: 0.5 @ 0.5) asLayoutFrame .
    sub := Morph new color: Color red.
    m1 addMorph: sub fullFrame: frame.
    m1 extent: 300@300.
    m1 openInWorld.