Is that healthy to write long commands?

Asked by Eugene S

Greetings,

I'm not sure whether this question is Siluli oriented or of a more general type. But I will try.
Ususally, when I needed to locate a pattern within specific area or relative to another pattern, I would follow steps that look like that (in this case I want to locate and lick in a button that is loctaed from right to a pattern):

1. pat = find("pattern.png")
2. pat.highlight(1)
3. patR = pat.right()
4. patR.highlight
5. but = patR.find("button.png")
6. but.highlight(1)
7. but.click()

However, it is also possible to do all this just in one line, which makes the code more easy to maintain. So to rewrite the above lines:

find("pattern.png").highlight(1).right().highlight(1).find("button.png").highlight(1).click()

This works perfectly but for some reason I'm not sure if that's the better way to do that. Can someone advise or share his opinion on such way of organizing the code? Is that safe/healthy or maybe more prone to errors in a way I haven't discovered yet?

Thanks!
Eugene S

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Both options are ok and have their pro's and con's

*** option 1 (line by line)
you would use this normally during workflow design and testing and of course, if you need the intermediate regions later in the workflow.
On crash, you get the causing line as a more detailed feedback, than with option 2.

Wether you convert option1 code to option2 code after it works depends on your needs.

BTW: in version 1.0.1+ you have Settings.Highlight=True for debugging purposes, so every match is highlighted for 2 secs (Settings.DefaultHighlightTime=N (value >= 1).

So for testing purposes this would be enough:
Settings.Highlight=True
pat = find("pattern.png")
patR = pat.right()
but = patR.find("button.png")
but.click()

... and if it works, simply switch to False

*** option 2 (dotted chain)
... surely has the advantage, that it can be read and understood similar to a sentence in natural language.
... and it makes the scripts shorter

But it makes debugging a bit harder.

Again the "highlight" version
Settings.Highlight=True
find("pattern.png").right().find("button.png").click()

Revision history for this message
Eugene S (shragovich) said :
#2

Hi RaiMan,
Thank you for your quick reply and EXTRA useful info about highlight!

Eugene

Revision history for this message
Eugene S (shragovich) said :
#3

Thanks RaiMan, that solved my question.