#Coding Guidelines

0 Followers · 56 Posts

Recommendations and best practices for writing code.

Question Yuri Marx · Nov 24, 2020

Hi community!

Is it possible generate HTML documentation to my project ObjectScript classes (.cls)?

In Java we use Javadoc to do it. Javadoc get class comments and java metadata information and when I execute javadoc -d doc src\*, I get whole html documentation to my classes. Has IRIS something like javadoc? Is it documatic? If yes, how can I use it?

12
2 799
Question Ahmad Bukhtiar · Nov 19, 2020

I have multiple files with different columns, first 9 values are fixed, so i want to ignore the first value, and next 8 values i want to combine into one value using ^ sign

Current Format

|||||||||||^^||||||^^|||||||||||||||||
|||||||||||^^||||^^|||||||||||||||||||||||
|||||||||||^^|||^^||||||||

Desired Format

^^^^^^|||^^||||||^^|||||||||||||||||
^^^^^^|||^^||||^^|||||||||||||||||||||||
^^^^^^|||^^|||^^||||||||

Reading each line from the file use below code.

#dim line as %String = tInput.ReadLine(, .status)

"here i was to put some string function to change format of the data in line variable"

11
0 995
Question Ahmad Bukhtiar · Sep 23, 2020

Any syntax help, i want to check different msg types and then reach out to the value in that particular segment. Here is example, i want to get SSNNumber from a method. Trying to use NOTIN, and Lookup

Class Training.RulesFunctionSet Extends Ens.Rule.FunctionSet

{

ClassMethod getEmiratesId(pHL7 As EnsLib.HL7.Message) As %String
{
SET msgType = pHL7.GetValueAt("MSH:MessageType.TriggerEvent")
 

IF msgType NotIn "A39,A40,O01,O11,O09,R01" {
return pHL7.GetValueAt("PID:SSNNumberPatient")}

5
0 704
Question Oliver Wilms · Jun 3, 2020

Hello,

I work on deploying IRIS inside Docker container. I really like %Installer class can automate many steps. I want to establish an ECP connection to a mirror database and then define a remote database on the application server. I have already seen we can create local database and namespace in %Installer. What code is needed to establish ECP connection?

6
0 712
Question Ken Earl · Jul 25, 2020

I have been looking into using abstract classes and methods. In other languages, if a superclass is defined as abstract, subclasses inheriting from the superclass will not compile until all abstract methods have been implemented in the subclass.
I have created the following classes to try this in Cache:
Class User.Music.AbstractClass [ Abstract ]
{

             Method testabs(inp As %String) [ Abstract ]{}

}

Class User.Music.AbstractTest Extends (User.Music.AbstractClass, %Persistent)

{    

           Method testabs(inp1 As %Integer!!,"Input:",$g(inp,"undefined"}

}

8
0 1495
Question Kurro Lopez · Jun 12, 2018

Hi all,

I'm wonder what could be the best way convert the sentence "Switch" C# into Cache code.

int caseSwitch = 1;

switch (caseSwitch)
{
    case 1:
    Console.WriteLine("Case 1");
    break;

    case 2:
    Console.WriteLine("Case 2");
    break;

    default:
    Console.WriteLine("Default case");
    break;

}

My first attempt was:

set caseSwith = 1

if (caseSwith = 1)
{
   w "Case 1"
}
else
{ 
  if (caseSwith = 2) 
  { 
    w "Case 2"
  }
  else
  {
      w "Default case"
  }
}  

16
1 3113
Question Oliver Wilms · Feb 7, 2020

I understand RecordMaps can be used to send delimited files through a production without custom coding. The data segments are delimited by tilde character followed by $Char(10) in Linux/Unix. When I test the same IO data in Windows, I have $Char(13) and $Char(10) instead of just $Char(10). I like to use just tilde character for record delimiter and ignore $Char(13) and $Char(10) between the tilde and the leading data of the next segment / record. Is this good idea or not if someone wants to generate classes will it override code? I believe in X12 schema it ignored leading control characters.

2
0 1097
Announcement Eduard Lebedyuk · Sep 10, 2019

Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that implements a certain algorithm.

Here's a list of Code Golf competitions we had on Developers Community.

And some interesting challenges:

Did I miss something? Add more challenges in comments.

0
0 493
Discussion Evgeny Shvarov · May 1, 2019

Hi Community!

Sometimes I meet a method which accepts 10+ parameters.

And often I need only the 8th parameter  to  pass. And I call the method something like:

do ##class(Some.Feature).Method(,,,,,,,"flag")

And I don't like this method when I call it like this cause, you know, often I just miss the number of commas and raise some other flag I wanted.

How do you avoid this situations? 

If you meet such a code, how do you call it and sure that you didn't miss the number of ","?

What is a good number of parameters in a method and f you need to pass more parameters in a method what do you do?

27
1 1800
Announcement Sourabh Sethi · Jul 29, 2019

A SOLID Design in Cache Object

In this session, we will discussing SOLID Principle of Programming and will implement in a example.
I have used Cache Object Programming Language for examples.
We will go step by step to understand the requirement, then what common mistakes we use to do while designing, understanding each principles and then complete design with its implementation via Cache Objects.

If you have any questions or suggestions, please write to me - sethisourabh.hit@gmail.com

CodeSet - https://github.com/sethisourabh/SolidPrinciplesTraining

7
2 547
Question Sergio Martinez · Aug 6, 2019

Hi,

I have a method that has multiple parameters and is normally used from other classes in ObjectScript. Most of the parameters have default values. Withing the server code that's perfect. In some areas I can call myMethod(,,"sometext") or myMethod(tVariab) and thats fine... I use it as it's required in each place.

But now I want to expose it as a REST service so I need to buld a kind of wrapper., another method in a REST dispatcher class that will receive the parameters in a JSON object and will call the server method already implemented. Something like:

3
0 1004
Question Murillo Braga · Jun 17, 2019

Hi guys,

I have never used regular expressions with caché object script before, so I've read through the documentation, but I am struggling with things that I'd like some help on.

My need is to identify specific html tags and transform them out to something else. Example:
I need to identify those guys in a wider string:
"<span style=\""font-family: '';font-weight: bold;\"" >BOLD TEXT</span>"
"<span font-style:italic;\" >ITALIC TEXT</span>"

And then they'll become:
"<b>BOLD TEXT</b>"
"<i>ITALIC TEXT</i>"

4
0 583
Question Thembelani Mlalazi · Jun 3, 2019

Say I have a property in  a persistent class that stores list of colours and I would like to query that field and return  a list and be able to loop that list to get individual colours how will l go about achieving this I have tried something like this but its not working as expected

 &sql(SELECT colour INTO :colourList FROM favouritecolours)
 While (SQLCODE = 0) 
{
 for i=1:1:$LENGTH($P(colourList,","))
 {
 set fvalue=$P(colourList,",",i) 
write "the first"_fvalue,i, 
} 
}

 

the query returns colours but its just a string no delimiter eg;

green red blue

 

I have tried with

1
0 573
Discussion Daniel Tamajon · Mar 19, 2019

Hi! We have received a request to create a new rule on CachéQuality to identify when a developer uses double quotes (" ") within any SQL statement.

We have been asked many times about SQL validation rules, and we would like to open a debate to allow everyone discuss what would you like to be checked on a SQL statement.

Current examples are for basic situations:

  • Using SQL.Statement class:

Set stmt = ##CLASS(%SQL.Statement).%New()
Set query = "Select Val1, Val2 FROM Table WHERE Val1=""SomeCondition"""

  • Using embedded SQL
13
0 636
Question Daniel Lee · Feb 18, 2019

I am new to Intersystems Cache, so please bear with me. We are using HealthShare 2013.1. 

I have a routine to compare databases from separate instances where I want to ignore values that begin with %sqlcq. I thought this would be easy with pattern matching operator '?' but it is proving difficult and it seems to be because of the percent character. 

For example:

set x = "%sqlcq.something.value.foo"

#;does not evaluate as true. 
if x?1P1"sqlcq" {write "valid"}

set y="sqlcq.something.value.bar"

if y?1"sqlcq".E {write "valid"}
valid
if x?1"sqlcq".E {write "valid"}

  
4
0 544
Question Laura Cavanaugh · Feb 5, 2019

Our development server is set up to automatically keep the .INT code of compiled classes and routines, but the live servers are set to not keep the .INT code.

I know how to set the system to keep this code ($SYSTEM.OBJ.SetQualifiers() ?)  but what are the ramifications of keeping this code on the live servers?  Is it just a space issue?  I always thought it was to keep the code more private.

4
0 676
Question Vivek Ranjan · Sep 28, 2018

Method1(){

Set OID1=##class(Table).%OpenId(100)

// do Kill OID

}

&SQL(Update Table Set  Column=88)

Method2(){

Set OID2=##class(Table).%OpenId(100)

// Or do %Reload()

Set OID.Column=99

Do OID.%Save()

}

// Column 1 still holds value as 1

For getting the updated value I should do Kill OID in Method1

4
0 672
Announcement Daniel Tamajon · May 21, 2018

As a developer, usually I'm concerned about how my code health is, and how the other coders code can affect to my own work.  And I'm quite sure most of us feel very similar.

In our company we use a Static Code Analysis tool to analyze code for different languages to ensure we are writing high quality and easily maintainable code by following a few best practices in terms of code structure and content. And the question was: why should be different for Caché ObjectScript language?

3
4 1199
Question John Murray · Feb 13, 2018

Documentation here lists the kinds of members a class definition may contain. In summary:

  • Parameters
  • Methods
  • Properties
  • Class queries
  • XData blocks
  • Projections
  • (and some that are relevant only for persistent classes):
    • Storage definitions
    • Indices
    • Foreign keys
    • SQL triggers

Later in the same document, a section headed "Class Member Names" contains this warning:

So I'm interested to hear how other DC members handle this.

7
0 418
Question Thembelani Mlalazi · Jan 30, 2018

I am trying to write an application that will take some information on the database make a call to the Google API distance matrix and get the information to use with rest of the application without using the ensemble part of the development is this possible and how can I do my communication with the  API from a cache class thanks in  advance

7
0 1447
Article Evgeny Shvarov · Mar 9, 2016 2m read

Hi!

Here is small "How to" again.

Suppose you need to share something with source code. How can we manage it on DC?

Sharing code snippets

1. Add normal post (not Code Package).

2. Paste your code in the post and format it with highlighting as it is described here.

3. If you see that your COS code is highlighted wrong it means that autodetect missed with language. Open the post's HTML ("disable rich-text" button below the Editor) and put class=COS parameter into the code tag.

Example:

2
0 546