Dasharo / open-source-firmware-validation

OSFV infrastructure with automated tests and scripts for managing test results
Apache License 2.0
9 stars 1 forks source link

Variable syntax #517

Open krystian-hebel opened 1 month ago

krystian-hebel commented 1 month ago

https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Using%20variables%20with%20keywords%20creating%20or%20accessing%20variables specifies 3 forms of variables, 2 of them are highly recommended over the third one, due to possible double expansion. Virtually all of our keywords use the form that is not recommended.

Is there a reason behind this choice? If not, would it be worth to switch to shorter, recommended form and see what breaks?

SergiiDmytruk commented 1 month ago

Not sure about all uses, but $var should be used in all Python expressions (parameters of IF, WHILE, etc.) instead of current '${var}' or '''${var}''' which break on some inputs. That way Python gets an actual variable with the value instead of dumb text substitution (docs, it's part of fork; they put it in the appendix even after translations and wonder why nobody knows about it...). The variables are typed, so conversions to numbers or strings will be necessary at times, but it's not a bad thing to compare numbers as numbers.

Overall, Robot Framework has the worst syntax I've ever seen (if not compared to Brainfuck and alike) and when there is a good way of doing things, there are also several bad ways of doing the same and the documentation is far from being good. That might be the reason why syntax which isn't recommended is used all over the place.

Update. See https://github.com/Dasharo/open-source-firmware-validation/pull/501#discussion_r1784336221 for an example of special $var syntax not working.