Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

ObjectScript for non Cach Programmers mumps

VIEWS: 13 PAGES: 19

									    ObjectScript for
non-Caché Programmers


       Ian Cargill
Dendrite Clinical Systems
                 ObjectScript
•   Descendant of Mumps
•   Old-style code can look very strange
•   New-style code can look almost as strange
•   Very „loose‟ rules
•   No variable declaration
•   Very little compile-time error detection
•   Paucity of on-line resources
 Globals and global variables
• Global - permanent storage
• Global Variables - Public variables
  –   visible to all?
  –   Yes and no.
  –   Confused and surprising
  –   All rather „reverse logic‟ to a non-Mumps
      programmer.
          Caret Character: ^
• ^ indicates a Global: ^Value
• ^ indicates a Routine: ^MyFunction
• Slightly confusing for beginners
  – Set x=^Value
  – Set x=$$^MyFunction
        Everything is a string
•   Typeless language?
•   Yes and No!!!!!!!
•   Automatic Casting in code
•   Telephone numbers lose leading „0‟
                 "Procedures"
•   Routines - "Module"
•   Procedures - scoped, public/private, return value
•   Subroutines - public, no return
•   Functions - public, return value
•   Methods - In Objects (Class/Instance)
                        Scope 1
• 'Classic' Scope
  – No braces, { }
  – Very open, by default everything public
  – Strange way of restricting scope: New
     • New (var-list)         Exclusive
     • New var-list           Inclusive
                    Scope 2
•   New Style, scope using {} and []
•   More like other languages
•   BUT, still a little strange to beginners!
•   Several 'gotchas' to watch out for
    MyFunction(params) {
       // even public ("global") vars masked!
    }
                 Scope 3
• Xecute, @, &sql use only public variables.
• Won't work inside { } !!
• Need to 'punch a hole' with []
  MyFunction(params) [var1,val,SQLCODE] {
    Set x=@var1
    @sql(SELECT Fld INTO :val FROM X.Y …)
    Quit:SQLCODE<0 "FAIL"
  }
                    Quit
• Be careful – Quit is a bit overloaded
• Quit loop – Argumentless
• Quit Function (like Exit OR return)
  – Argument or Argumentless
  – Must match call
         Call Syntax - 1
TEST()         A   TEST           B
   code here          code here
  Quit               Quit

TEST()         C   TEST           D
   code here         code here
  Quit "OK"         Quit "OK"
            Call Syntax - 2
                     A             B             C

                 <PARAMETER>       OK        <PARAMETER>
Do ^ROU

                     OK        <PARAMETER>       OK
Do ^ROU()

                 <COMMAND>     <PARAMETER>       OK
Set x=$$^ROU()
             Call Syntax - 3
• $QUIT
  – What sort of Quit is required to exit from the
    current context

  – 0: Argumentless            Quit

  – 1: Argmemented             Quit "OK"
 Setting and Killing Variables
• Kill – strange to non-Mumps programmers
• Important cleanup tool, esp. for Objects
             MACs, INTs
• Similar, but MAC can contain embedded
  SQL, macros and embedded HTML.
• MAC precompiled to INT
• INT compiled directly onto OBJ code
• Error Line Numbers always correct for INT,
  probably not for MAC!
• View Other, but beware.
      Postconditional Syntax
• Command:condition

• Quit:count>10
    $Get() is your friend & enemy
•   Caché has no variable declaration
•   <UNDEFINED> everywhere!
•   $Get() saves a lot of runtime errors BUT
•   Can cover up a lot of problems, too!!
               Use the Force
•   $Order, $Query
•   $Length, $Piece
•   $Extract
•   $ZConvert, $ZTranlate,
•   Mix classes (tables) and Globals
            Error Handling
• Old Style tricky
  – Set $Ztrap=“ErrorLable”


• New Style (Caché 5.1 onward?)
  – Try / Catch
  – Not perfect, but much improved

								
To top