On 29-9-2018 14:02, Adriano dos Santos Fernandes wrote:
Mark, saying that an object-based interface is better to store state or
the way to support external routines is disregard how good Firebird
selectable procedures are.
Selectable procedures stores intermediary states in a very elegant way.
I am worried that it disallows (or at least complicates) more complex
implementations of aggregate functions, and may not work so great when
used with sliding windows. My first aggregate proposal wouldn't work
well for that either, the second proposal could possibly be extended in
a similar manner as PostgreSQL does.
However, I have to admit, not having written a lot of aggregate
functions, I'm having a hard time coming up with good examples to be
able to consider both designs.
It's also the way modern languages implemented the same concept
recently, say JavaScript (ecmascript) and C# with yield.
Do you know of an equivalent example in those languages, because I can't
easily think of an equivalent aggregate function in a similar style in
either JavaScript or C#.
Aggregate functions are a combinations of an accumulator and a
'finisher' (and maybe a combiner if you want to be able to parallelize),
and trying to combine those two is more complex (and I think it makes it
brittle to write, so more susceptible to bugs).
My second proposal will make it purely functional, separating the
concerns of accumulating and finishing.
My propose is to use the same elegant concept for aggregation. Your
example seems much more confusing. It makes sense thinking on
interfaces, but very different from Firebird way of doing things.
It may need to have a different syntax, although I tried to follow the
package body syntax in my example for consistency.
Also, it does not use pass-by-reference concept. It uses underlying
Firebird mechanism of messages, the same used for initial parameters
values and return values. PSQL syntax may be changed to.make it more
clear that it's not a parameter by reference.
From the perspective of the one writing the PSQL function, it does seem
to be using a pass by reference: the value of the parameter can be
changed from outside while within the loop, which is something entirely
new for PSQL.
Mark
--
Mark Rotteveel
Firebird-Devel mailing list, web interface at
https://lists.sourceforge.net/lists/listinfo/firebird-devel