On Mon, Jun 12, 2017 at 7:22 AM, Glenn Hoetker <ghoetker@me.com> wrote:
Hi all. Iâm new to Pharo and loving it. As I transition from a text-file based mindset, Iâm a little stuck and would appreciate help in how to think about a situation in a Pharonic (Pharo-ish, Pharoc?) way.
Iâm crafting a short program to help me process a large text file (specifically: extract, sorting, and regularizing the âkeywordâ fields of a large BibTex file). Especially since I donât really know what Iâm doing, working in a Playground has been a great development environment. Now that the program is complete (under 30 lines, wonderful), I want to be able to save it for future reference (and perhaps for future use). If Iâd written a shell script, Iâd just save âfixBibDeskKeyWords.shâ to a directory. Iâm not sure what to do in the Pharo environment, thought.
At the moment, it just lives in the Playground Iâve developed it on. I could save the image and leave that Playground open, but Iâm just positive thatâs not a best practice. I also worry about what happens if I closed/cleared that Playground by accident.
I think I understand that, if I created a new package, I could use Monticello to save it to a local cache and load it into a new image whenever I needed it. But, given that itâs short, highly specialized and fairly linear, the idea of creating a âGHBibDeskStuffâ package with one class (âGBibDeskKeywordFixerâ containing a single âFixFileâ method seems really heavy and awkward.
Can one save the contents of a Playground in a Pharonic way? Is there a better approach?
Thank you to all involved in this wonderful programming ecosystem. I appreciate any advice.
Great to hear you are enjoying Pharo. The heavy part of saving to disk as a Monticello package is an optional secondary step, but to make you code "permanent" in the image you do need a class to hang it on, and a package to hold that. Doing this only in-Image is quite light and quick to do, and makes it easy to find later. In a System Browser create package "GHBibDeskStuff", class GBibDeskKeywordFixer. Create your method so you can use it from playground like this... GBibDeskKeywordFixer new fixFile. Then to the class side of GBibDeskKeywordFixer also add a method #fixFile like this... GBibDeskKeywordFixer class >> fixFile self new fixFile. so that from playground you can drop the "new" and use it like this... GBibDeskKeywordFixer fixFile Feels like you've added a new command to Pharo? Note that "GBibDeskKeywordFixer class >>" is just a documentation convention indicating you should click the <Class> button to add a method to the class-side. cheers -ben