-
Notifications
You must be signed in to change notification settings - Fork 40
Description
This is an open question for current json-api users:
Would it be worth it to remove the distinction in the current filter syntax in which binary operators get their operator "infixed" (i.e., placed in the middle, like (x,gte,4)
) but other operators get their operators placed at the beginning (e.g., (and,(...),(...))
)? Instead, the operator would always be the first item.
The advantages of this are:
-
It becomes easy for a binary operator to add extra, optional operands down the line. E.g., imagine you want to extend the
lte
operator to support "chained comparisons". So, instead of saying(and,(0,lte,minDistance),(minDistance,lte,maxDistance))
, you want to support something like(lte,0,minDistance,maxDistance)
. In the current setup, supporting this would change where the parser is expectinglte
operator to be, because it's no longer a binary a binary operator. So, either you couldn't change it (and would create a new operator instead), or the change would break existing users, or you'd have to complicate the parsing and serialization logic further to support both forms (i.e.,(x,lte,y)
and(lte,x,y)
). -
Related to the above, the parser and serializer (in progress) already have to special case binary operators. In this simplification, those special cases could be removed, and operators also wouldn't have to be defined with whether they're binary (though perhaps they still could be defined with their arity to enable automatic validation of the length of the arguments list).
-
Forcing the infixing of binary operators was intended to offer better usability, and it probably does on the whole. However, the forced infixing sometimes leads to really unreadable results. E.g., there's an operator that takes a center point and a radius and returns a circle value that can be used as an operand to the
geoWithin
operator (to find resource objects inside that circle). Because this operator is binary, it has to be infixed, so you end up with([0,0],toGeoCircle,100)
. That's pretty cryptic. (The first arg is the center and the second is the radius.) It'd probably be clearer to have(geoCircle,[0,0],100)
, as that reads more like a standard function call.
The disadvantages are:
-
This is a break from the existing format. Big mitigating factor: people could continue to use the current version of the parser package while still updating the json-api lib to the latest version — which is very nice!
-
Most binary operators, which are the most common case, probably get a bit less readable, if you accept that that people find it easier to read
(a,gte,b)
than(gte,a,b)
.