Share And Share Alike With RSE
September 17, 2014 Susan Gantner
In my last tip, Decisions, Decisions: Templates Or Snippets?, I discussed taking advantage of both Templates and Snippets. They are used to make life simpler when including small pieces of code that might otherwise be copied from another source member somewhere or, worse yet, rewritten from scratch over and over again.
Once you’ve created a few templates and/or snippets, your fellow developers may ask you to share the wealth. So how do you do that? There are Import and Export options for both Snippets and Templates. They work a bit differently, however.
Remember that Templates are created via the Preferences dialog. (Hint: key “Templates” in the search box.) That’s also the starting point for sharing them. If you navigate your way in Preferences to the Templates for your language of choice–probably ILE RPG for most Four Hundred Guru readers–you’ll see buttons to the right of the template list for Import and Export. Select one or more templates (use the Control key for multiple), and then click on Export. You will be prompted for a file name and location to save the XML that will contain the description of the selected Template(s). You should store this exported file on a shared drive somewhere so that your fellow developers could get to it.
For your fellow developers to get your Templates, they simply need to get to the same Preference page for ILE RPG and select the Import button. They can then browse to the location where your export file is stored and open it to get them. There doesn’t seem to be a way to import specific templates. One simply gets all of the ones in the file. While I’ve never done it myself, one option may be to edit the XML file before importing it to remove the ones you don’t want to import.
In my experience, RSE will import templates even if your workspace already has one of the same name just as long as template itself is not identical. You may find after importing that you end up with multiple templates of the same name, so it may be wise to modify the names and/or descriptions to make it obvious which is which or, of course, delete one of them if you don’t need both. If the template is identical to one that is already there, the import process doesn’t duplicate it.
To export your Snippets, you’ll need to use the Customize option from the Snippets view – the same way you create a new Snippet. Next select the Category that contains the Snippets you want to export, which enables the Export button. A dialog asking for a file location for the XML export file appears, as it did for templates. Similarly, the person importing the snippets uses the same Customize dialog to import, browsing to the export XML file location and opening it.
The most significant difference between sharing Snippets compared to Templates is that with Snippets you must Export (and Import) an entire category, not individual ones. Another difference is that when importing the Snippets, if the same category already exists in the workspace, you will get a warning message asking if it is OK to overwrite the existing “drawer” (an alternative name for the category). Be careful. It will completely replace the entire category if you say OK, potentially causing you to lose all Snippets that were previously in that category in your workspace unless they were also in the export file.
So when it comes to sharing Snippets, planning ahead is a good idea. You may want to create a special category for shared Snippets to keep them separate from each developer’s individual collection, assuming that not all developers will want to share all of the Snippets in the shop. To do this you will probably want to take advantage of the fact that you can Copy and Paste Snippets from one Category (or Drawer) to another. This is done from the context menu (right click) in the Snippets view directly, not in the Customize dialog.
One sharing scenario might be that each developer has their own category/drawer for their personal Snippets and they can each import the “Shared Snippets” category. After importing, they can copy the ones they want to use from the shared drawer into their own drawer to avoid the need to search both drawers. This also makes it easier to control the sequence of the Snippets, which is done within a category by the Move Up/Move Down buttons in the Customize dialog. To avoid the potential confusion of having duplicate Snippets in different categories, they can choose the option to “Always hide” the Shared Snippets category. Then whenever new shared Snippets are exported by their fellow developers, they can re-import the Shared Snippets category without concern that they will lose any of their own personal collection.
One final point before I close. You can improve your snippets view by selecting layout from the context menu in the Snippets view and choose Details, which brings in the more detailed text descriptions into the view. As your Snippets collection grows, it will make it easier to find the one you need for a particular task.
Susan Gantner is half of Partner400, a consulting company focused on education on modern programming and database techniques and tools on the IBM i platform. She is also a founding partner in System i Developer, a consortium of System i educators and hosts of the RPG & DB2 Summit conferences. Susan was a programmer for corporations in Atlanta, Georgia, before joining IBM. During her IBM career, she worked in both the Rochester and Toronto labs, providing technical support and education for application developers. Susan left IBM in 1999 to devote more time to teaching and consulting. Together with Jon Paris, she now runs Partner400, and appears regularly at many technical conferences, including System i Developer’s RPG & DB2 Summit. Send your questions or comments for Susan to Ted Holt via the IT Jungle Contact page.