SlideShare a Scribd company logo
The 12 step guide to
    LotusScript
       Bill Buchan
           hadsl
#1: How to Code

•   How to code
    •   Code for maintenance
         • Code updates cost more than new code

    •   Architect well. Get the data model right to start with.
•   Only code for performance, if required
    •   Get it working before getting it working for speed
•   Why?
    •   The highest cost in development is software maintenance
    •   Make it easier for the person maintaining the app
    •   It could be YOU



                                                             2
#2: How to Test

•   Test soon, test often, test completely
    •   Look at test-driven development
         • Write the specification

         • Write the structure
         • Write the tests
         • Write the code

    •   Automatic testing means:
         • Far easier to regression test all the time

    •   Minimize run-time errors by:
         • Always assuming that data operations outside the
           current database may fail
         • Trapping all run-time errors and providing an execution
           path that fails safely
                                                           3
#2: How to Test (cont.)

•   Why test early?
    •   Costs rise as the tests fail further away from development
    •   Cheapest to most expensive are:
         • Unit tests — by the developer
         • User acceptance tests (UATs) — by the tester
         • End-user failure — by the user

    •   The more tests you perform in unit testing:
         • The cheaper your development will be

         • The more professional your colleagues will think you are
         • The more your boss will like you




                                                           4
#3: “Measure Twice, Cut Once”

•   Spend more time thinking and less time coding
•   Think of at least TWO methods of solving a problem
    •   The best approach is usually a blend of the two
    •   Think about the data model!
•   Why?
    •   More planning, less work
•   “You know it’s been a rough night
    when you wake up next to some
    code you don’t recognize.”
    	

 – Bob Balaban



                                                          5
#4: Option Declare

•   You should always use “Option Declare”
•   Yes, but why?
    •   If not, all variables are created at run-time as variants
          • This makes type-checking redundant
          • Data conversion costs ten times more performance!
          • And means all errors will be run-time errors

    •   Remember: Test lots, test early
    •   Use the strengths of the compiler to help you
    •   Remember to always declare the type of variables and
        parameters - otherwise it defaults to variants!




                                                             6
#5: The List Operator
Dim Pres list as String
Pres(“George”) = “Bush”
Pres(“Bill”) = “Clinton”

Print “Georges’s last name is: “ + Pres(“George”)
if not isElement(Pres(“Chad”)) then print “Chad wasn’t
found”
forall thisPres in Pres
	
  Print listtag(thisPres) + “ “ + thisPres
end forall

•   List stores a value with a unique lookup key
    •   Pros:
         • It’s easy and it’s fast

         • It’s built right into LotusScript, since v4.5
    •   Cons:
         • You can’t directly read and write a list from a document
           item – convert to an array first
                                                            7
#6: Defensive Coding

•   Defensive coding is:
    •   Assume the worst, check all input
         • On every function

    •   Does this affect performance? Not usually.
    •   A typical function looks like:

Function mytest(p1 as String, p2 as String) as
integer
	
  mytest = false
	
  if p1=”” then exit function
	
  if p2=”” then exit function
	
  ...
	
  ' Now actually do something!
	
  ....
	
  mytest = true
end function

                                                     8
#7: Extending Arrays the Easy Way
Sub   initialize()
	
    Dim myArray() as String
	
    redim myArray(0)
	
    call myExtend (myArray, “Hello Sailor”)
end   sub

function myExtend(S() as String, ns as String) as integer
   if (S(ubound(S)) <> “”) then redim preserve S(ubound(S)+1)
   S(ubound(S)) = ns
   extend = true
end function



•     Pros:
      •   No need to keep separate index of array size
      •   Automatically “trims”
•     Cons:
      •   Slow with large arrays
      •   Need to define some “empty” value
                                                           9
#8: Logging

•   If you have applications with scheduled Agents
•   Or, if you have a diverse range of clients
    •   Then, you need to log your Agent (both client and
        scheduled) run-time status
•   Why?
    •   Applications will break
    •   You need to know when they break
    •   Timing metrics for performance testing
•   Beware!
    •   Don’t make the logging
        so slow that it affects
        application performance!

                                                            10
#8: Logging (cont.)

•   OpenLog is an OpenNTF Project:
     •   www.openntf.org
•   It provides a framework for collecting error logging
     •   To use in your database:
          • Copy the script libraries from the OpenLog database
          • Update the code:

    Function test(param1 as String) as integer
    	
  Test = false
    	
  on error goto errorhandler
    	
  ' ...
    	
  Test = true
    exitFunction:
    	
  exit function
    errorhandler:
    	
  call logError()
    	
  resume exitfunction
    end function
                                                           11
#8: Logging (cont.)

•   Example OpenLog output:




                              12
#9: Use NotesDateTime Instead of Strings!

•   Don’t store date/time values as Strings
•   Use NotesDateTime structures, and save them
•   Why?
    •   You don’t know how the client will interpret dates
          • Is it dd/mm/yyyy or mm/dd/yyyy?
    •   It means that views will be able to sort on dates
•   This happens more often than you think!
    •   And things always break on the 13th of the month




                                                             13
#10: Always use full canonical names in
reader/author fields!

•   Common names assume the same hierarchy as the
    server in use
•   Abbreviated names dont work
•   Always use multi-values for multiple names - sticking ‘;’
    between names wont work
•   And always set the field to reader/author in
    LotusScript!




                                                     14
#11: Evaluate

•   Evaluate allows you to run @Functions within
    LotusScript
•   Sometimes faster, easier
•   Example:	

    	

 	

     	

  evaluate(|@unique|)
•   DON’T:
    •   Overuse it. Lots of LotusScript functions mimic @functions
         • strRight == @StrRight




                                                          15
#12: “Trusted Servers”

•   Scheduled Agents cannot normally open databases on
    other servers
    •   “Trusted Servers” field in R6 server document, security
        section allows servers to “trust” other servers
    •   This allows you to centralize “collection” Agents
    •   Caveat: Don’t trust servers in another domain!
•   Pros:
    •   Simplifies architecture
    •   Fewer Agents
•   Con:
    •   Relies on fast, reliable network infrastructure …


                                                            16
#13: LSI_Info()/GetThreadInfo

•   LSI_INFO() gives some run-time information
•   Superceded by GetThreadInfo
    •   GetThreadInfo(11) gives calling class
    •   GetThreadInfo(10) gives function name
    •   And lots more
•   Why?
    •   Error trapping: We can track where we came from
    •   We don’t have to pass lists of parameters to error
        trapping code
    •   Prevents “cut-n-paste coding” errors ...



                                                             17
#13: LSI_Info()/GetThreadInfo (cont.)
                                             	
 ' calling code...
                                                 ...
                                             ExitFunction:
                                                 exit function
                                             errorhandler:
                                                 Call RaiseError()
Function RaiseError()                            resume exitFunction
	
  Dim thisType As String                   end function
	
  Dim es as String
	
  thisType = Typename(Me)
	
  	
 
     ' Not a class, use the calling module instead
     If (thisType = "") Then 	
  thisType = Getthreadinfo(11)
	
  	
 
	
  es = thisType & "::" & Getthreadinfo(10) & ": "

	
     If (Err = 0) Then
	
     	
  es = es + "Manually raised an error"
	
     Else
            es = es + "Run time error: (" + Trim(Str(Err)) + ") " + _
	
     	
  Error$ + " at line: "+ Trim(Str(Erl))
        End If

	
  Print es
end function
                                                                18
Okay
I added a new step


               19
Done!
        20

More Related Content

PPTX
Php extensions
PDF
Learn To Test Like A Grumpy Programmer - 3 hour workshop
PPTX
A brief to PHP 7.3
PDF
ShaREing Is Caring
PDF
PHP7 - The New Engine for old good train
PDF
Php7 傳說中的第七隻大象
PDF
TypeProf for IDE: Enrich Development Experience without Annotations
PPTX
introduction to server-side scripting
Php extensions
Learn To Test Like A Grumpy Programmer - 3 hour workshop
A brief to PHP 7.3
ShaREing Is Caring
PHP7 - The New Engine for old good train
Php7 傳說中的第七隻大象
TypeProf for IDE: Enrich Development Experience without Annotations
introduction to server-side scripting

What's hot (20)

PDF
Preparing code for Php 7 workshop
PDF
Functional Programming for Busy Object Oriented Programmers
PPTX
002. Introducere in type script
PPTX
Reviewing CPAN modules
PDF
PHP 7.1 : elegance of our legacy
PDF
Type Profiler: Ambitious Type Inference for Ruby 3
PDF
The secret of PHP7's Performance
PPTX
Php internal architecture
PPTX
CPAN Exporter modules for Perl 5
PDF
Louis Loizides iOS Programming Introduction
PDF
iOS Programming Intro
PDF
Go for SysAdmins - LISA 2015
PDF
Async await...oh wait!
PDF
What is the Joomla Framework and why do we need it?
PDF
TypeScript Best Practices
PDF
Static Analysis of PHP Code – IPC Berlin 2016
PPTX
PHP from soup to nuts Course Deck
PPT
Ruby For Java Programmers
PPTX
Php extensions
PPTX
Ruby basics
Preparing code for Php 7 workshop
Functional Programming for Busy Object Oriented Programmers
002. Introducere in type script
Reviewing CPAN modules
PHP 7.1 : elegance of our legacy
Type Profiler: Ambitious Type Inference for Ruby 3
The secret of PHP7's Performance
Php internal architecture
CPAN Exporter modules for Perl 5
Louis Loizides iOS Programming Introduction
iOS Programming Intro
Go for SysAdmins - LISA 2015
Async await...oh wait!
What is the Joomla Framework and why do we need it?
TypeScript Best Practices
Static Analysis of PHP Code – IPC Berlin 2016
PHP from soup to nuts Course Deck
Ruby For Java Programmers
Php extensions
Ruby basics
Ad

Viewers also liked (11)

PDF
AD1279 "Marty, You're Not Thinking Fourth Dimensionally" - Troubleshooting XP...
PDF
Connect 2016-Move Your XPages Applications to the Fast Lane
PDF
D8 l55g formation-introduction-a-ibm-lotus-domino-8-5-xpages
PPTX
MWLUG 2016 : AD117 : Xpages & jQuery DataTables
PDF
AD1542 Get Hands On With Bluemix
PDF
IBM Connect 2016 - AD1548 - Building Responsive XPages Applications
PDF
What the App? : A Modernization Strategy for Your Business Applications
PDF
XPages and jQuery DataTables: Simplifying View Creation while Maximizing Func...
PPTX
A Beard, An App, A Blender
PDF
Using Cool New Frameworks in (Mobile) Domino Apps
PDF
Building Responsive Applications Using XPages
AD1279 "Marty, You're Not Thinking Fourth Dimensionally" - Troubleshooting XP...
Connect 2016-Move Your XPages Applications to the Fast Lane
D8 l55g formation-introduction-a-ibm-lotus-domino-8-5-xpages
MWLUG 2016 : AD117 : Xpages & jQuery DataTables
AD1542 Get Hands On With Bluemix
IBM Connect 2016 - AD1548 - Building Responsive XPages Applications
What the App? : A Modernization Strategy for Your Business Applications
XPages and jQuery DataTables: Simplifying View Creation while Maximizing Func...
A Beard, An App, A Blender
Using Cool New Frameworks in (Mobile) Domino Apps
Building Responsive Applications Using XPages
Ad

Similar to Speed geeking-lotusscript (20)

PDF
12 Step Guide to Lotuscript
PDF
The View - The top 30 Development tips
PDF
Lotusphere 2007 AD505 DevBlast 30 LotusScript Tips
PPT
BP206 - Let's Give Your LotusScript a Tune-Up
PDF
The View - Lotusscript coding best practices
PDF
Dev buchan 30 proven tips
PDF
Top Tips Every Notes Developer Needs To Know
PDF
Ad505 dev blast
PDF
Lotuscript for large systems
DOC
QTP Online Training
DOC
QTP Training
PDF
The View - 30 proven Lotuscript tips
DOC
Qtp (basics to advanced)
PDF
Everything you ever wanted to know about lotus script
DOC
Qtp training in hyderabad
PPTX
MWLUG 2014: ATLUG Comes To You
PDF
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
DOC
Qtp Summary
12 Step Guide to Lotuscript
The View - The top 30 Development tips
Lotusphere 2007 AD505 DevBlast 30 LotusScript Tips
BP206 - Let's Give Your LotusScript a Tune-Up
The View - Lotusscript coding best practices
Dev buchan 30 proven tips
Top Tips Every Notes Developer Needs To Know
Ad505 dev blast
Lotuscript for large systems
QTP Online Training
QTP Training
The View - 30 proven Lotuscript tips
Qtp (basics to advanced)
Everything you ever wanted to know about lotus script
Qtp training in hyderabad
MWLUG 2014: ATLUG Comes To You
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Qtp Summary

More from Bill Buchan (20)

PDF
Dummies guide to WISPS
PPTX
WISP for Dummies
PDF
WISP Worst Practices
PDF
Marykirk raft race presentation night 2014
PDF
Dev buchan best practices
PDF
Dev buchan leveraging
PDF
Dev buchan leveraging the notes c api
PDF
Dev buchan everything you need to know about agent design
PDF
Entwicker camp2007 calling-the-c-api-from-lotusscript
PDF
Entwicker camp2007 blackberry-workshop
PDF
PDF
PDF
Admin2012 buchan web_services-v101
PDF
Reporting on your domino environment v1
PDF
Admin camp 2011-domino-sso-with-ad
PDF
Softsphere 08 web services bootcamp
PDF
Connections Lotusphere Worst Practices 2013
PDF
Lotusphere 2009 The 11 Commandments
PDF
Lotusphere 2008 Worst practices
PDF
Lotusphere 2008 - Jumpstart 206 - Web Services Bootcamp
Dummies guide to WISPS
WISP for Dummies
WISP Worst Practices
Marykirk raft race presentation night 2014
Dev buchan best practices
Dev buchan leveraging
Dev buchan leveraging the notes c api
Dev buchan everything you need to know about agent design
Entwicker camp2007 calling-the-c-api-from-lotusscript
Entwicker camp2007 blackberry-workshop
Admin2012 buchan web_services-v101
Reporting on your domino environment v1
Admin camp 2011-domino-sso-with-ad
Softsphere 08 web services bootcamp
Connections Lotusphere Worst Practices 2013
Lotusphere 2009 The 11 Commandments
Lotusphere 2008 Worst practices
Lotusphere 2008 - Jumpstart 206 - Web Services Bootcamp

Speed geeking-lotusscript

  • 1. The 12 step guide to LotusScript Bill Buchan hadsl
  • 2. #1: How to Code • How to code • Code for maintenance • Code updates cost more than new code • Architect well. Get the data model right to start with. • Only code for performance, if required • Get it working before getting it working for speed • Why? • The highest cost in development is software maintenance • Make it easier for the person maintaining the app • It could be YOU 2
  • 3. #2: How to Test • Test soon, test often, test completely • Look at test-driven development • Write the specification • Write the structure • Write the tests • Write the code • Automatic testing means: • Far easier to regression test all the time • Minimize run-time errors by: • Always assuming that data operations outside the current database may fail • Trapping all run-time errors and providing an execution path that fails safely 3
  • 4. #2: How to Test (cont.) • Why test early? • Costs rise as the tests fail further away from development • Cheapest to most expensive are: • Unit tests — by the developer • User acceptance tests (UATs) — by the tester • End-user failure — by the user • The more tests you perform in unit testing: • The cheaper your development will be • The more professional your colleagues will think you are • The more your boss will like you 4
  • 5. #3: “Measure Twice, Cut Once” • Spend more time thinking and less time coding • Think of at least TWO methods of solving a problem • The best approach is usually a blend of the two • Think about the data model! • Why? • More planning, less work • “You know it’s been a rough night when you wake up next to some code you don’t recognize.” – Bob Balaban 5
  • 6. #4: Option Declare • You should always use “Option Declare” • Yes, but why? • If not, all variables are created at run-time as variants • This makes type-checking redundant • Data conversion costs ten times more performance! • And means all errors will be run-time errors • Remember: Test lots, test early • Use the strengths of the compiler to help you • Remember to always declare the type of variables and parameters - otherwise it defaults to variants! 6
  • 7. #5: The List Operator Dim Pres list as String Pres(“George”) = “Bush” Pres(“Bill”) = “Clinton” Print “Georges’s last name is: “ + Pres(“George”) if not isElement(Pres(“Chad”)) then print “Chad wasn’t found” forall thisPres in Pres Print listtag(thisPres) + “ “ + thisPres end forall • List stores a value with a unique lookup key • Pros: • It’s easy and it’s fast • It’s built right into LotusScript, since v4.5 • Cons: • You can’t directly read and write a list from a document item – convert to an array first 7
  • 8. #6: Defensive Coding • Defensive coding is: • Assume the worst, check all input • On every function • Does this affect performance? Not usually. • A typical function looks like: Function mytest(p1 as String, p2 as String) as integer mytest = false if p1=”” then exit function if p2=”” then exit function ... ' Now actually do something! .... mytest = true end function 8
  • 9. #7: Extending Arrays the Easy Way Sub initialize() Dim myArray() as String redim myArray(0) call myExtend (myArray, “Hello Sailor”) end sub function myExtend(S() as String, ns as String) as integer if (S(ubound(S)) <> “”) then redim preserve S(ubound(S)+1) S(ubound(S)) = ns extend = true end function • Pros: • No need to keep separate index of array size • Automatically “trims” • Cons: • Slow with large arrays • Need to define some “empty” value 9
  • 10. #8: Logging • If you have applications with scheduled Agents • Or, if you have a diverse range of clients • Then, you need to log your Agent (both client and scheduled) run-time status • Why? • Applications will break • You need to know when they break • Timing metrics for performance testing • Beware! • Don’t make the logging so slow that it affects application performance! 10
  • 11. #8: Logging (cont.) • OpenLog is an OpenNTF Project: • www.openntf.org • It provides a framework for collecting error logging • To use in your database: • Copy the script libraries from the OpenLog database • Update the code: Function test(param1 as String) as integer Test = false on error goto errorhandler ' ... Test = true exitFunction: exit function errorhandler: call logError() resume exitfunction end function 11
  • 12. #8: Logging (cont.) • Example OpenLog output: 12
  • 13. #9: Use NotesDateTime Instead of Strings! • Don’t store date/time values as Strings • Use NotesDateTime structures, and save them • Why? • You don’t know how the client will interpret dates • Is it dd/mm/yyyy or mm/dd/yyyy? • It means that views will be able to sort on dates • This happens more often than you think! • And things always break on the 13th of the month 13
  • 14. #10: Always use full canonical names in reader/author fields! • Common names assume the same hierarchy as the server in use • Abbreviated names dont work • Always use multi-values for multiple names - sticking ‘;’ between names wont work • And always set the field to reader/author in LotusScript! 14
  • 15. #11: Evaluate • Evaluate allows you to run @Functions within LotusScript • Sometimes faster, easier • Example: evaluate(|@unique|) • DON’T: • Overuse it. Lots of LotusScript functions mimic @functions • strRight == @StrRight 15
  • 16. #12: “Trusted Servers” • Scheduled Agents cannot normally open databases on other servers • “Trusted Servers” field in R6 server document, security section allows servers to “trust” other servers • This allows you to centralize “collection” Agents • Caveat: Don’t trust servers in another domain! • Pros: • Simplifies architecture • Fewer Agents • Con: • Relies on fast, reliable network infrastructure … 16
  • 17. #13: LSI_Info()/GetThreadInfo • LSI_INFO() gives some run-time information • Superceded by GetThreadInfo • GetThreadInfo(11) gives calling class • GetThreadInfo(10) gives function name • And lots more • Why? • Error trapping: We can track where we came from • We don’t have to pass lists of parameters to error trapping code • Prevents “cut-n-paste coding” errors ... 17
  • 18. #13: LSI_Info()/GetThreadInfo (cont.) ' calling code... ... ExitFunction: exit function errorhandler: Call RaiseError() Function RaiseError() resume exitFunction Dim thisType As String end function Dim es as String thisType = Typename(Me) ' Not a class, use the calling module instead If (thisType = "") Then thisType = Getthreadinfo(11) es = thisType & "::" & Getthreadinfo(10) & ": " If (Err = 0) Then es = es + "Manually raised an error" Else es = es + "Run time error: (" + Trim(Str(Err)) + ") " + _ Error$ + " at line: "+ Trim(Str(Erl)) End If Print es end function 18
  • 19. Okay I added a new step 19
  • 20. Done! 20