The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Scripting in Workspaces

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Scripting in Workspaces Posted: Jul 7, 2004 12:55 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Scripting in Workspaces
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement
Over the years, I've observed Smalltalkers take advantage of the "workspace" to a variety of degrees. Some use it lots; some don't. This is not a post arguing whether you should or shouldn't.

I use it primarily for system maintenance/introspection scripts. Little code fragments that I don't feel warrant making new objects and models from. Doing so, there's two nifty tools I really like.

WorkspaceFormatting

Any script with a couple of do:'s or nested ifTrue:ifFalse: statements can get funny to read/modify quickly. WorkspaceFormatting is a goodie in the Open Repository which allows you to highlight a chunk of workspace code and "format" from the context menu, the same way you would a method in a class. I'm pretty sure it was Peter Hatch who authored it.

For me, this little tool is a big win, especially with any multiline workspace script. Years ago, I gave up wasting time formatting my own Smalltalk code and have never felt better. And this allows me to write readable scripts.

Blocks as Functions

If you written any normal scripts, you know that any appreciably complex script will want to be able to use "functions", usually because your performing the same unit of work from multiple call sites. One can accomplish this by using blocks stored in script variables. For example:

countPrerequisites := [:pkg | pkg deploymentPrerequisites size].
Store.Registry allPackages do: 
		[:each | 
		Transcript
			cr;
			show: ('<1p> has <2p> prerequisites' expandMacrosWith: each
						with: (countPrerequisites value: each))]

The first line declares a block which can act like a function for later uses in the script. Kind of like a poor man's method for scripts.

We could have inlined that. Until we have multiple call sites in the script it's probably not worth it except maybe for maintainability. What cannot be inlined though would be a recursive function. One of the not as often used properties of the full closure block, is that it can refer to and call itself. As in:

wholePrereqTree := 
		[:pkg | 
		| all |
		all := Set with: pkg.
		pkg deploymentPrerequisites do: 
				[:coll | 
				(Store.Registry packageNamed: coll first) 
					ifNotNil: [:subPkg | all addAll: (wholePrereqTree value: subPkg)]].
		all].
Store.Registry allPackages 
	groupedBy: [:each | (wholePrereqTree value: each) size]

In this one, the wholePrereqTree block invokes itself to recursively walk the prereq tree. For tree structure models like store and the class hierarchies, I've gotten a lot of mileage out of this technique.

Read: Scripting in Workspaces

Topic: Security in a rush environment Previous Topic   Next Topic Topic: Real Smalltalk

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use