Before someone asks, there was no meet-up posted for yesterday (@eastgate and @satikusala were both away). A few folk turned up and we had an ad hoc and unrecorded session.
Taking a question from @archurhh as our start, we looked at user-defined functions in Action code, using the aTbRef section Functions as a framework with @echuck giving some helpful deeper insight on the process.
As a result I’ve already made a few clarifications to the above articles and have some more to do. The subject might be one to cover again in a recorded meeting.
A few key takeaways:
- Not everyone needs (to use) functions. If you don’t use them, that is OK
- If trying to learn functions, first find a task where a function might help. IOW, the process is quite abstract, especially those not grounded in much programming or scripting.
- But, if you’ve dabbled in action code for rules, agents, etc., you’ve met most of the building blocks already.
- Functions assist in code re-use, i.e. rather than N stamps/rules running the same code, all can call a single function. This also makes it easier if a later fix/improvement is needed for that code.
- Functions can help make shorter, clearer code. A case in point is where it is necessary to use action code at the head of an export template. Pushing most of the code logic out into one or more functions means less scrolling to see the actual export code. Plus, library notes have action code syntax colouring, export templates do not.
- What makes sense when we write it, may make less sense in six months’ time. Just like adding a Description for new user attributes, some comments in your function code will repay that small effort.
- Remember the first bullet above - if you don’t need functions, don’t worry that you’re missing out!