Pharo Wiki
repository·master·Indexed 42 days ago
https://github.com/pharo-open-documentation/pharo-wikiComprehensive 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.
What's inside Pharo
- 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.
Choose a Pharo source code export format
masterPharo 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
Feature Tonel (Recommended) FileTree metadata less FileTree metadata full Best for New projects, Windows users, Iceberg users Method-level history Legacy/Monticello use Granularity One file per Class One file per Method One 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.
Discover Pharo community external resources
masterThe 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) |Keep a collection sorted using SortedCollection
masterIf you need a collection that remains sorted as new elements are added, use
SortedCollection. Unlike standard collections,SortedCollectionautomatically maintains order upon insertion.Warning: Use
SortedCollectiononly when necessary, as it can impact performance during addition and removal operations compared to standard collections.Ways to create a
SortedCollection:- Transform an existing collection using
#asSortedCollectionor#asSortedCollection:. - 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)"- Transform an existing collection using
Follow the wiki entry structure and conventions
masterWhen 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:
CodeHandle stream positioning and encoding errors
masterIn 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 encodingerror.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 ].Understand Traits for behavior composition
masterTraits 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.
Understand Keyword messages
masterA keyword message involves a receiver and two or more objects (the arguments). The arguments are part of the message selector and must be preceded by a colon (
:).13 between: 12 and: 14Declare a launcher for external scripts
masterA 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.Compose traits into new traits
masterTraits are composable. You can create a new trait that uses one or more existing traits using the same syntax used for classes.
Trait named: TMyComposedTrait uses: TMyFirstTrait + TMySecondTrait package: 'MyPackage'Use the Meta tab to explore class hierarchy and methods
masterThe
Metatab 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.
Use ProportionalLayout for responsive submorph sizing
masterA
ProportionalLayoutallows submorphs to resize proportionally when the container morph changes size. This is achieved by assigning aLayoutFrameto a submorph, where the frame represents a percentage of the parent morph's dimensions.To implement this:
- Set the container's
layoutPolicy:toProportionalLayout new. - Define a frame using
asLayoutFramewith coordinates ranging from0to1(e.g.,0 @ 0 corner: 1 @ 1represents 100% coverage). - 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.- Set the container's