April 18, 2019

Is it really the Easy Custom Functions?

The ACF in ACF plugin stands for Advanced Custom Functions, but we could also call it the Easy Custom Functions – in the sense that it is easier to create more complex functions in the ACF language.

I converted a huge Custom Function to ACF – and I realised one thing. After using a lot of time only to analyse the functionality of the old function – the person created it must have been using a lot of time creating and debugging it. Then when someone needs to do some changes to it, it is almost untouchable. Even the person has probably done what he could to make it readable. Doing anything to it was tough.

When I had converted it to ACF – it was easy to understand what the function does and how it does it. It was even easy to implement some changes to it.

The purpose of the function was to create a SQL statement based on some 25 parameters. The goal of the change was to optimise the produced SQL so it would run faster when applied to the database. The converting to ACF and the resulting SQL was a significant improvement and the time for executing the SQL reduced dramatically.

I probably spent much less time converting it to ACF and implement the changes there, than trying to achieve it in the old function as it was.

I removed the recursion from it, using loops instead. The block structure made it easier to read – than counting semi-colons to see where something stops and starts in deeply nested if-constructs.

When we talk about complex functions, to build it as a procedure that creates a result, it returns as a function value makes readability much better and maintenance more comfortable — compared to the upside-down thinking to build it all as a colossal calculation.

We could make it as a script instead. But as scripts cannot run from a calculation. This particular Custom Function I converted, is used in several field calculations in the table definition. It becomes a snap-in replacement instead of re-designing the whole flow.

Leave a Reply

Your email address will not be published. Required fields are marked *