cos-guidelines icon indicating copy to clipboard operation
cos-guidelines copied to clipboard

ordering arrays

Open daimor opened this issue 10 years ago • 10 comments

instead of with getting next index in the end of loop

set ind=$order(array(""))
for {
    quit:ind=""

    /// some code here
    set ind=$order(array(ind))
}

should be

set ind=""
for {
    set ind=$order(array(ind))
    quit:ind=""

    /// some code here
}

daimor avatar Dec 14 '15 07:12 daimor

IMHO, it's more like best practices, not code style guidelines.

adaptun avatar Dec 14 '15 08:12 adaptun

Agreed with Sasha @adaptun here - it's more suitable to future "Best Practices" Wiki. Same as with #10

tsafin avatar Dec 14 '15 08:12 tsafin

Both loops above are fine. I wouldn't recommend one more than the other. The first style gives you the ability to quit before entering the loop, but there are 2 $order functions. The second style only has one $order function, but you always enter the loop.

isc-solon avatar Dec 23 '15 16:12 isc-solon

In any way you entering the loop, and in second style, you also can quit before $order, but I don't see any way why it should be needed. One main idea, is, in first variant, you can't use continue, because you should first get a next value by $order, and after that you code will be unreadable. And in "right" variant, you can go to next value in any place of your loop.

set ind=""
for {
    set ind=$order(array(ind))
    quit:ind=""
    quit:ind="end"
    continue:$get(array(ind,"skip"))

    /// some code here
}

daimor avatar Dec 23 '15 16:12 daimor

We can start filling BESTPRACTICES.md as well

eduard93 avatar Dec 23 '15 19:12 eduard93

@eduard93 we could start witth MD file, but I still believe that Wiki pages would be easier to maintain and navigate for this kind of content.

tsafin avatar Dec 23 '15 19:12 tsafin

@tsafin GitHub project wiki eg. MDX2JSON wiki is just another repo with md files, so I see no point in maintaining two repos with text files instead of one. default

eduard93 avatar Dec 23 '15 19:12 eduard93

Or instead of wiki possible to use Read the docs, one of examples here

daimor avatar Dec 23 '15 19:12 daimor

Although their markup might be the same, but from usabiliy point of view Wiki is much more convenient to use (especially for well structured hierarchy). IMVHO

tsafin avatar Dec 23 '15 20:12 tsafin

@daimor but Read the docs looks nice. But this is external dependency, which might eventually disappear.

P.S. If time permits we need to play with this tool though.

tsafin avatar Dec 23 '15 21:12 tsafin