MGLStyleValue should be reimplemented as a subclass of or wrapper around NSExpression, and MGLStyleLayer layout and paint properties should accept NSExpressions instead of MGLStyleValues.
Especially once we introduce support for arbitrary arithmetic and conditional expressions in style values (mapbox/mapbox-gl-js#4077 and possibly mapbox/mapbox-gl-js#4079), maintaining a custom vocabulary and type system around these values will become a major burden. Though it’s nice that the current MGLStyleValue system is strongly typed, taking better advantage of type inference in Swift, our API surface area and the learning curve will increase quite a bit as we essentially try to reinvent a statically-typed NSExpression.
NSExpression performs runtime type checking for initialization and static type checking for inspection. For maximum developer comfort, it features a format string mini-language and a series of strongly-typed getters that are applicable to certain kinds of expressions. MGLVectorStyleLayer takes advantage of all these features by representing filters as NSPredicates, which consist of NSExpressions. As with NSPredicate, developers are already familiar with NSExpression and its format string syntax, so there won’t be much of a learning curve at all.
The one thing NSExpression doesn’t provide is the concept of a style function. It does provide a rather awkward extensibility mechanism; we could extend NSExpression to understand functions and provide a more ergonomic, strongly typed API for working with functions. For constant values and expressions, the developer would use NSExpression directly. #5970 (comment) has a sketch of the proposed API.
My understanding is that mapbox/mapbox-gl-js#4077 would require a style specification version bump, which would precipitate an SDK major version bump, so we probably don’t need to worry so much about backwards compatibility for this refactoring.
/cc @boundsj @incanus @lucaswoj @jfirebaugh
MGLStyleValue should be reimplemented as a subclass of or wrapper around NSExpression, and MGLStyleLayer layout and paint properties should accept NSExpressions instead of MGLStyleValues.
Especially once we introduce support for arbitrary arithmetic and conditional expressions in style values (mapbox/mapbox-gl-js#4077 and possibly mapbox/mapbox-gl-js#4079), maintaining a custom vocabulary and type system around these values will become a major burden. Though it’s nice that the current MGLStyleValue system is strongly typed, taking better advantage of type inference in Swift, our API surface area and the learning curve will increase quite a bit as we essentially try to reinvent a statically-typed NSExpression.
NSExpression performs runtime type checking for initialization and static type checking for inspection. For maximum developer comfort, it features a format string mini-language and a series of strongly-typed getters that are applicable to certain kinds of expressions. MGLVectorStyleLayer takes advantage of all these features by representing filters as NSPredicates, which consist of NSExpressions. As with NSPredicate, developers are already familiar with NSExpression and its format string syntax, so there won’t be much of a learning curve at all.
The one thing NSExpression doesn’t provide is the concept of a style function. It does provide a rather awkward extensibility mechanism; we could extend NSExpression to understand functions and provide a more ergonomic, strongly typed API for working with functions. For constant values and expressions, the developer would use NSExpression directly. #5970 (comment) has a sketch of the proposed API.
My understanding is that mapbox/mapbox-gl-js#4077 would require a style specification version bump, which would precipitate an SDK major version bump, so we probably don’t need to worry so much about backwards compatibility for this refactoring.
/cc @boundsj @incanus @lucaswoj @jfirebaugh