When I first saw the proposal of chaining methods in LotusScript, I couldn't connect it with my current knowledge of LS. This probably has something to do with the fact that I'm a copy-paste/reinventing the wheel type of programmer. I just recently started making script libraries. Before that, most agents I wrote, contained all the code it needed.
We have had several internal discussions in our programming department about using classes/not using classes, using standard script libraries for the most common operations and so on. We mostly agree that it's a good idea, but we never seem to get any further than that.
Anyways, back to the topic (sorry).
I'm currently working on a new database for our company's website. One of the tasks that involved, was making a routine that copies documents about out employees from one database, to the website (to avoid doing updating the same information twice, if someone quits/we get a new employee).
When I started writing the agent that should do this (empty local view/copy from employee db) the website with the employee db, I remembered the article by Tim Tripcony.
“What if I could simplify this into one or two lines of code?”.
I first built a script library that contained the methods that I needed (I could probably just have asked a colleague, but ..reinventing the wheel). Then I made sort of an interface-class, that made all the functions in the script-library “chainable”.
What I ended up with was kind of mindblowing for a person that copy-pastes most of his code.
I added a line-break after each method-call, to increase readability.
Dim operations As New ChainedOperations
Call operations._
useCurDb()._ 'selects current db
useVw("someview")._ 'select view
remAllEntr(False)._ 'deletes all entries in view (don't force)
cleanUp() 'sets all temporary variables=Nothing
Call operations.useDb("someserver","somepath")._ 'select a specific db
useVw("someotherview")._ 'select view
copyAllWithFilter("Field|", s.CurrentDatabase)._ 'copy all except those with “Field”=“”
cleanUp() 'clean up </span>
Example Scripts (naming of script-libraries is to easier see structure):
Com
Com.ChainedOperations
The example agent
1 comments:
My Java agent one liner:
http://dominounlimited.blogspot.com/2006/10/l33t-java-agent-one-liner.html
Not very practical, it but works :)
Post a Comment