Replies: 3 comments 1 reply
-
I personally think that this verb+connector should not be added to every binary operation (thinking about |
Beta Was this translation helpful? Give feedback.
-
As a suggestion, I would like to recommend that any DataWeave function or operator which expects a lambda function and iterates over a given list should always provide the current For example, |
Beta Was this translation helpful? Give feedback.
-
On the Binary Functions section, I want to reiterate the importance of infix notation. This chain-ability makes code so much more readable and clean. I'd say any function that takes more than two arguments, such as Even if they can't, the consistency of the argument pattern is important. Developers shouldn't have to go read the docs every time they want to remember the order of arguments for a function. |
Beta Was this translation helpful? Give feedback.
-
Functions in DW
Naming is one of the hardest things and more subjective things in programing languages. Over the years we have added functions into
the DW language without a clear guideline and we have spent to many hours discussing the naming of them. The idea of this document is
to have a guideline (it doesn't need to be perfect) so that we can have consistent naming. The idea is that we will look for new functions will be adopted without our consumers to suffer for the least astonishment principle.
We should also define some guidelines for how parameters should be set (order), kind overloading and lambdas.
Basic principles
Binary functions
Binary functions (functions with two params) are the most common type of functions in DW. We should optimize this functions
for infix notation. What does this mean.
Examples:
Let's look at some examples from the dw::core::Arrays
Usage:
On the other case we have partition
Though partition handles the null case the name doesn't follow the verb connector, so it is incosistent.
Usage:
In this case we should have follow a verb+connector like partitionWhen
Unary Functions
Unary functions are always prefix so here we should try to optimize readability for prefix case.
Other cardinality
There has been cases where other cardinality functions has been transformed to binary functions, an example of this is the
replace by using the with function connector. Though I think the end result reads really well it is very hard to understand the
signature and how they all work together
Very simple to read but very hard to understand that you need to use the with function unless you read the documentation.
I'm still not sure if we should follow this pattern that it has been also used on
dw::util::Values
in functions like update or mask.Instead a function like
replaceWith("a----b", "-", “")
it also reads good (follow the verb+connector) and it is not hard to understand how it works.Beta Was this translation helpful? Give feedback.
All reactions