fge
fge

Reputation: 121710

What does this recommendation mean on InterSystem Russia's github coding guidelines (macro)?

These coding guidelines mention (rightfully so, I believe) to "[...]insert spaces after comma in functions/methods argument list".

Follows an example, but then this comes after:

For obvious reasons this recommendation not applies to arguments in $$$macro-call, where such extra spaces will break final result.

I'm not a seasoned ObjectScript developer, far from it, so out of curiosity I tried this:

ClassMethod foo()
{
    #define concat(%1, %2) %1 _ %2
    w $$$concat("foo", "bar"), !
}

And when executing this method it returns the "expected" result:

foobar

So, what are those "obvious reasons" this recommendation is referring to?

Upvotes: 3

Views: 92

Answers (2)

rfg
rfg

Reputation: 1636

Another reason is that some macro expressions are evaluated till-first-whitespace, for example ##if

Upvotes: 2

DAiMor
DAiMor

Reputation: 3205

Developers are lazy, and we are not an exception. While macro-definitions so flexible, I can write a lot interesting things, to simplify development process. You can see one of my examples here at github.

#define NewTempGN(%gn,%i) set %i=$i(^CacheTemp.MyApp),%gn=$name(^CacheTemp.MyApp(%i))

you can't add space after comma, because this space also will appear before variable, and such code may became illegal syntactically.

$$$NewTempGN(gn, ii)
#; transform to
set  ii=$i(^CacheTemp.MyApp),gn=$name(^CacheTemp.MyApp( ii))

One more example

#define forAll(%gn,%key) set %key="" for { set %key=$order(@%gn@(%key)) quit:%key=""
#define forEnd }

#; some global structure which you want to write
set gn=$na(^mtemp("test"))
set @gn@("val1")
set @gn@("val2")
set @gn@("val1")

#; and simple use with macro
$$$forAll(gn,val)
   write !,val
$$$forEnd

Upvotes: 4

Related Questions