Hosted By

Contact Me

Misc Links

OpenNTF BlogSphere LotusGeek CoComment Custom Button

Ads by Google

Welcome to keithstric.com!

I hope you find this site useful in some way or another. I strive to bring you all sorts of geeky information and solutions to your most frustrating of issues with the occasional rant on whatever topic, technical reviews and weblog. You'll also find many products that I've developed and make available for you to use however you like. So, grab a cup of coffee, sit down and visit for a while.

« Annoying Spam... | Home Page| Time and Materials contracts »

How do you use Script Libraries

01/26/2009 8:58 PM By Keith Strickland

I've been working on this huge application that was written years ago and is full of hard coding of server/database names, email addresses, etc. These databases also usually have many script libraries that contain no functions, only sub-routines. These sub-routines do not return any values and mostly modify the values in a document somewhere. I really don't like this technique, I prefer to use functions that return a value, this way at least the function is kind-of reusable, even if it is only reusable within the specific application that it resides.

Now, to get around all the hard-coding I use a profile document whose sole purpose is for recording the path to the required application(s). I then developed a class with a few sub-classes which can be used within each of the applications to ease the maintenance burden of maintaining this application across multiple sites. This seems to be working fairly well it's just that there is a learning curve for using the classes. But this is kind-of off topic.

So, how do you prefer to use a script library, are they full of sub-routines which modify documents here and there or do you prefer to use functions which return a value? I understand that each has it's place, but to have 10 script libraries with 20 sub-routines within each library that is only called once seems like a waste of time, energy and space. What are your thoughts?


Comments

ID: 1
Date: 01/26/2009 11:19:53 PM
Name: Tony Palmer
Website: http://palmeweb.blogspot.com

Classes and using inheritance and delegation patterns means that you usually end up writing (and subsequently maintaining) less code. For configuration settings I have a context class, that I can get application specific settings. Internally I will either get the value from a profile document or standard look up - depending on what is the best for the data being accessed.

ID: 2
Date: 01/27/2009 12:07:46 AM
Name: Karl-Henry Martinsson
Website: http://www.bleedyellow.com/blogs/texasswede

I try to organize my script libraries after funktions and where I call them from. I am also (slowly) rewriting one of my biggest applications into classes.

So my script libraries are named something like this:

Declarations.Globals
Functions.Globals
Functions.Win32.Files
Functions.Win32.CommonDialogs
Functions.Email
Functions.XML
Class.FinancialTransactions
Class.ClaimData

etc...

The script libraries mostly contain functions, returning a value. There are some where I just call a sub routine, but I prefer in most cases to call functions from the main code.
I don't think you can have any general rule.

But even a function which modify a document should return a value, indicating success or failure. You have error handling in your function, so you return true or false depending on success or not.

For example, I have a function which create an email:

Function ManagerEmailNotification(user as string) as integer

I pass it the name of a user, and it in turn call another function:

GetManagerName(user as string) as string

This second function make a lookup into the NAB (using calls to my NAB class, located in script library Class.AddressBook) and return the manager name of the user passed.
I then compose a mail and perform a call to doc.Send. If an error triggers, the function return False, otherwise True.

Among the few Sub routines I have is one that add a standard disclaimer to the end of a rich text field:

Sub NoReplyMessage(rtitem as NotesRichTextItem)

This sub add a specified text (in red, bolded, and in specified font) to the rich text field passed. In that case a function would not work.
I proabbly should make it a function and do error trapping, but the code is so simple that I decided to slack off a little and skip that. I know, Bill and Rocky will kick my butt for even saying this... Emoticon


ID: 3
Date: 01/27/2009 08:44:30 AM
Name: Keith Strickland
Website: http://www.keithstric.com

@2 "I don't think you can have any general rule. "

I totally agree with this, you can't have a general rule. I was just checking as I thought it odd that out of all of those script libraries none of the subs/functions returned any values. When I was just learning, I'm sure I did this too. But I can't tell you how frustrating it is to find a sub that does basically what you want but you can't use it in the context you're wanting to because it goes out and modifies all these different documents, so you have to either 1. rewrite it or 2. create another function that does the same thing but will work in the context you need, which is a waste, at least in my eyes

ID: 4
Date: 03/04/2009 08:22:38 AM
Name: Simon Boulton
Website: http://

All I can do is echo @1 and @2. My LotusScript script libraries have nothing but classes. Yes, there is the problem of loading libraries where some (or even a lot) of the code is redundant, but by designing in an object-oriented fashion from the start, this problem can be ameliorated.

Agents and actions have only the minimum amount of code required to use the classes and their associated methods.

Since moving to this way of doing things, my code's reliability has improved, design changes are easier to implement and development times have decreased.

Incidentally, I don't use subs at all (apart from the new statement). As far as I can see, a sub is a function that doesn't return a value.

ID: 5
Date: 03/04/2009 08:39:26 AM
Name: Keith Strickland
Website: http://www.keithstric.com

@4 - While I am starting to move in the direction you're stating, you can't always rewrite something to be OO. You may inherit an application that is huge and done by someone just starting out in Notes development. Such as with this example, which makes it impossible to rewrite due to time/monetary constraints.

Also, I don't think everything should be contained in a class. Sure it does make things easier to maintain, more reliable and it does speed up development times, but sometimes using a class to do something menial is overkill, like killing a fly with a hammer.

"As far as I can see, a sub is a function that doesn't return a value." - I agree with this, if a sub should be used, I make it a function and try to make it at least return true/false to show that it completed or not.

Post A Comment

:-D:-o:-p:-(:-):-\:-|:angry::cool::cry::dontknow::emb::hairout::laugh::rolleyes::whew:;-)

Subscribe to keithstric.com

OpenNTF

Disclaimer

The opinions and ideas posted on keithstric.com are not necessarily the opinions and ideas of my employer. The solutions, techniques and code provided here are not guaranteed or warranted in any way and are free for you to use at your own risk.