Scripting style

Hello rextended!

I notice you do not use CamelCase ou camelCase in your variable names.
To me it is a bit hard to imagine why…

Could you elaborate a little on why?

Additional question:

I see that within your scripts you usually enter the configuration context and handle things there. Example:

/log
:global maxattampt 3
:global errorArray [:toarray ""]
:global failmsg  "login failure for user "
:global frommsg  " from "
:global viamsg   " via "
:global listfail "list_failed_attempt"
:foreach rlog in=[find where message~"((25[0-5]|(2[0-4]|[01]\?[0-9]\?)[0-9])\\.){3}(25[0-5]|(2[0-4]|[01]\?[0-9]\?)[0-9])"] do={
##supressed
}

And I prefer to use the entire path of the command every time:

:global maxattampt 3
:global errorArray [:toarray ""]
:global failmsg  "login failure for user "
:global frommsg  " from "
:global viamsg   " via "
:global listfail "list_failed_attempt"
:foreach rlog in=[/log find where message~"((25[0-5]|(2[0-4]|[01]\?[0-9]\?)[0-9])\\.){3}(25[0-5]|(2[0-4]|[01]\?[0-9]\?)[0-9])"] do={
##supressed
}

I believe that part of my preference for using the entire path of the command is due to my history with basic and bash.

But also, taking into account the historical in RouterOS break-changes, I tend to believe that this mitigates the script’s breaking resulting from changes in RouterOS syntax throughout the version updates.
Especially when script calls script.

What differences do you see in the two methodologies?
Is one better or worse? And why?

Simple: I act according to how I feel like it at that moment.

Since these are very simple scripts and not parts of the program that other collaborators would have to work on,
I give the variable names, apart from not using names already used in RouterOS for objects, the name that seems correct to me at that moment.

  1. anything that reduces (not excessively) the code is fine

  2. It is easier to correct a single line, if it changes the context as you wrote, rather than rewriting them all…

  3. it is less heavy and more readable.


    your example it’s a bit too simple…

use this: (camelCase // typeName because the script is complex)
/system clock
:global strDate [get date]
:global strTime [get time]
:global intGoff [:tonum [get gmt-offset]]
:global strDate [/system clock get date]
:global strTime [/system clock get time]
:global intGoff [:tonum [/system clock get gmt-offset]]
For me all repetitions of “/system clock” are completely unnecessary and make the code difficult to read,
and in case of changing the path of “/system clock” to something else in the future (as you have hypothesized and as has often happened),
I only need to change one line instead of all the instructions.