Search DominoPower's 11,437 Lotus-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
Recursion: the good, the bad, and the alternatives (continued)

That's why the big search engines use the queue method, because if they see the work queue getting bigger, they can either add more resources to process the queue quicker, prioritise items in the queue, or even dump stuff they deem irrelevant. Another advantage is that you can track where you have been and not re-visit places that have already been processed.

This is pretty important in regular recursion too, if there is a risk of circular referencing. If you are recursively searching Domino Directory groups (and nested groups), then this would be a must, as there is every likelihood that someone has put circular references somewhere.

A work queue in Domino could be, for example, a global list variable or a set of documents. The advantages of the document scenario is that it some code could continue where it left off on the next run and you have a persistent record of where your code has been, assuming you don't delete entries from the queue, but merely mark them as having been processed. You can decide which is the best approach.

Here's an example we'll discuss over the next few paragraphs:

1 Sub PrintAscii(sToPrint)

2 QueueEmpty = False
3 Erase masterlist
4 masterlist(sToPrint)=sToPrint
5 While Not QueueEmpty
6 QueueEmpty=True
7 Forall x In masterlist
8 Print Asc(Left$(x,1))
9 If Len(x)>1 Then
10 masterlist(Mid$(x,2))=Mid$(x,2)
11 QueueEmpty = False
12 End If
13 Erase masterlist(x)
14 End Forall
15 Wend

16 End Sub

This example uses a work queue called "Masterlist" to maintain what is next on the list of activities, as it works through the queue. As it progresses through the queue, it itself adds entries to the queue. Once it has gotten through the queue that it first started with, it checks the queue again in case any further items where added. It repeats that until the queue is empty and stays empty.

In line 3, we initialise a LotusScript list variable, masterlist. This will be the queue or list of work to be done. In the Web searching example, this would hold a list of Web addresses to be searched. As we search an address, we may find more links to search, which we would add to our list of things to do, but not immediately try to deal with it, as we would with recursion. A LotusScript list datatype is like a dynamic array, but we don't need to redim to expand it. Line 3 sets up the initial queue item. Then, we set up a loop to make sure the queue is processed until empty.

We use a Forall in line 7, but this isn't strictly necessary if we maintained our work queue using a data structure where we could easily pick the first item.

Lines 9 to 12 deal with adding a new entry to the queue to cover the "rest" of the string.

Line 13 removes the item from the work queue, as it has been processed. Then we loop round until the queue is empty. This is a horribly trivial example, but I hope it illustrates the point.

Conclusion
Recursion is a powerful technique but it has its limitations. These can be managed by careful programming and risks can be calculated to find out if there is a real risk of hitting them. There are also techniques to gain the effect, without the limitations. Alternatively, Java may be more appropriate for recursion that requires heavy depth.

Ian Murray is an independent Domino consultant of ten years, based in the UK. He has extensive experience of large scale infrastructure management, serving the most demanding of Domino applications. You can contact Ian on +44 7973 135939 or at ian.murray@dlcc-ltd.co.uk


« Previous  ·  1  ·  2  ·  3
Other articles you might like
Home > Lotus Technologies > LotusScript (64 articles)
   When the debugger won't debug hidden code that isn't hidden
   What to do if the LotusScript debugger won't single-step over code
   Little known traps about Lotus Notes fields
Home > Tips & Techniques (102 articles)
   More about Domino log files
   Why your log.nsf might not be purging properly
   A faster way to repair corrupted server files
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent DominoPower Articles
Application development, William Shatner, and the origin of the universe
Learn Domino Designer 8.5 for free
The (near) future of Sametime, Quickr, Connections, and Symphony
Inside the IBM Innovations lab
Lotusphere 2010: Hot fixes and cool news for Notes, Domino, and LotusLive
Lotusphere 2010: mobility and collaboration
2010: A Lotusphere of change
Latest Lotus Headlines
SNTT : XPages onclick Ghosts in the machine
Ports used by Lotus Sametime 8.5 servers
Exploring a Domino Date Bug
Adding Quick Highlighter support to IBM Lotus Notes Domino Wiki, Weblog, or Webpage
Remember Young Admins...there are 2 files
WebSphere Portal 6.1.0.2 and Lotus Domino 8.5
The CKEditor - with Domino
>> Read all the news
More from the ZATZ journals
Computing Unplugged: The iPad defenders have spoken
David Gewirtz Online: CNN commentary and analysis
OutlookPower: More about disappearing text
-- Advertisement --

Find unused Lotus Notes groups and clean up your address book
Have you ever wanted to get rid of old Lotus Notes groups that were cluttering up your address book, but you weren't sure if they were used? Find Unused Groups can help.

Find Unused Groups will check your ACL, mail, multi purpose and server groups to help you determine if they are used, and who uses them.

Learn how to easily clean up your address book.

-- Advertisement --

Mark your calendar for in-depth Lotus training, May 12-14, Boston
Join experts and peers May 12-14 in Boston for educational and networking events that deliver real-world Lotus training so you can increase productivity and efficiency in your company, advance your skills, and squeeze the most from your current environment. One registration gets you into THE VIEW's Admin2010 and Lotus Developer2010.

Register by April 10 to save $200.
ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login