google / cel-spec

Common Expression Language -- specification and binary representation
https://cel.dev
Apache License 2.0
2.83k stars 224 forks source link

CeL pure functions #240

Closed alexec closed 2 years ago

alexec commented 2 years ago

I love how the same CeL expressions can be run in many languages, allowing you to reuse your expressions in many places. There are many use cases for this.

I want whole functions, so I can have if statements, for loops etc.

Today I can only see two options: WASM or JavaScript (most langs have a JS interp).

That’s a shame. A simple programming language would be awesome.

So my question is, what would you do?

TristonianJones commented 2 years ago

@alexec I think it depends on your goals. If you want a full language that's portable and sandboxed, then I would use a full language and not CEL. In practice, it's incredibly hard (almost impossible) to constrain the upper bound of an expression's compute and memory when you introduce loops and functions as first class syntactic features.

In terms of statements and single line functions, it's possible to provide a layer on top of CEL that is able to provide such functionality, e.g. Firebase Rules. However, such languages usually set hard and fast limits at runtime that are product-specific which means they can be difficult to debug when they fail.

tl;dr. If you have a narrowly defined product with a good reason for a domain-specific language, then feel free to create it but be very careful about the sorts of compute / memory impacts you expose yourself to by doing so. Usually, if you're entering this feature territory, you should just use a full blown language and use something like WASM to achieve sandboxing and portability.