· Mar 28, 2020

Why Declarative ObjectScript is not a framework/tool but a matter message

DISCLAIMER: I am not an InterSystems engineer or a professional ObjectScript developer.

I just want to share my opinion about some things I am really miss in ObjectScript.

I really appreciate everyone who support my project (Declarative ObjectScript) in contest

but the post is not about "why you should support me" on contest.

I faced with ObjectScript in the university while was working on my diploma (in 2013).

Very good mentor @Evgeny Shvarov helped me to get started with ObjectScript development.

In those days I was surprised about ObjectScript doesn't support passing methods to another methods as arguments.

Today is 2020 and ObjectScript is still doesn't support this while the most popular programming languages do.

Even Java support this but the Java is so much conservative programming language! :-)

I really miss this feature in ObjectScript. I thought I am alone in my "suffering"....

But! Thank to Contest (and thank to @Evgeny Shvarov again) I've seen one special project - ObjectScript-Foreach by @David Crawford.

He made a project which allows you to pass a method to a for-each loop. Fantastic! Really thank you @David Crawford !

ClassMethod METHODNAME(pMes) As %Status
	write pMes, !
	return $$$OK
USER>set YOUR_VARIABLE = ["some","thing"]
USER>do ##class(Iteration.Loop).Foreach(YOUR_VARIABLE,"METHODNAME")

I think it is a sign. A message to a community and to an engineers who work on ObjectScript.

A message about ObjectScript needs such feature.

My project (Declarative ObjectScript) gives you an example how it could be implemented in the most painless way (on my opinion).

It works on very simple algorithm:

  1. Add special comment on method
  2. Extend class which holds the method from DeclarativeOS.RegistryHelper
  3. Use one of provided "operations": $zfilter, $zmap, $zcount, $zesists, $zfnd, zforeach and $zjoin.
  4. Enjoy it :)

One of the example looks like that:

Class Demo.App Extends DeclarativeOS.RegistryHelper 
 /// @Declarative("examples:isEven") 
 ClassMethod IsEven(number As %Numeric) As %Boolean 
     return number # 2 = 0 
 ClassMethod RunWithDeclarativeOS() 
     set numbers = ##class(%ListOfDataTypes).%New() 
     for i=1:1:4 { do numbers.Insert(i) } 

     set evenNumbers = $zfilter(numbers, "examples:isEven") // sexy and short

     write "Even numbers: " _ $zjoin(evenNumbers, " ") // printing collection
 ClassMethod RunWithLegacyCode() 
     set numbers = ##class(%ListOfDataTypes).%New() 
     for i=1:1:4 { do numbers.Insert(i) } 

     set evenNumbers = ##class(%ListOfDataTypes).%New() // iterate explicitly
     set index = "" 
     for { 
         set index = numbers.Next(index) // working with indexes
         set item = numbers.GetAt(index) 
         if (item # 2 = 0) { 
             do evenNumbers.Insert(item) 

     write "Even numbers: " 
     for i=1:1:evenNumbers.Count() { write evenNumbers.GetAt(i) _ " " } // printing collection

My vision that it could it be implemented on the language level to support this feature.

Compiler or some "processor" may:

  1. scan all codebase of the project and find out all methods with such comments: /// @Declarative(...)
  2. store in some system or "service" global all information about found methods (package name + class name + method name)
  3. define special "operations" via %ZLANGC01 and %ZLANGF01
  4. these "operations" does all magic (resolve declarative call by its name and do stuff which is requested to).

That is my opinion. Thank you to read to the end.

If you missed my fun promo then you should see it by https://www.youtube.com/watch?v=EXSXF1-q1LU.

Do you think ObjectScript becames better with such feature?
Discussion (2)0
Log in or sign up to continue

Maks, thank you for your words, I appreciate! And thanks for the participation in the contest - your entry and video are very bright! 

Speaking about ObjectScript - maybe one day we can set up a contest for "BetterScript" or collaborative project which will include all the "wishes" community introduced during the last 10 years.  And I hope it is possible assuming that fact ObjectScript first compiles into INT script and then into OBJ. 

With your permission I will add some useful links on the topic: