Comments (2)
Hello,
Let me explain the difference.
It may seem what expr and goja solves a similar problem, but they do it in a little bit different way. Also use cases can be different, goja targets more environments where JS may be needed, Expr on the other hand targets rule engines, filtering, and policy of different kinds.
A few differences between goja and expr:
-
Main difference is that Expr can be type checked. Expr comes with advance type checker which can use type defined directly in Go program. This is very useful, for example, if you want users to allow editing expressions in UI and on save button your program can type check the new expression and warn of any errors found.
-
goja/otto implement full JS, so you need to be aware of what users can write: infinite loops
while(true);
, self-recursions, an so on. Expr is non-Turing complete and has limited set of functionality available for users. Expr also has more expressive syntactic sugar, for example predicatesall(tweets, .size <= 280)
. Also, in Expr you have full control other the language and what features available to users. -
Patching. Another powerful tool in Expr is AST patching (expr-lang.org/docs/patch). Patching allows to modify expressions in any possible form before compilation. A lot of companies use this powerful feature in a lot of different ways.
-
Expr designed to be working with Go. Expr does not wrap values and uses them directly. As goja is JS vm, goja has to wrap all passed values into
Value
struct (sometimes with strange consequences) and unwrapExportTo
. -
Speed. As Expr was designed specifically for Go and with business rule engines/expressions in mind, Expr is faster than goja/otto (bench). Expr uses own virtual machine, Expr has optimizing compiler, and Expr uses a few tweaks to speed up the Expr/Go communications.
-
Expr is dependencies free. Check out Expr's go.mod file. Expr has zero dependencies; this makes auditing process is much easier, easier to upgrade.
Both Expr and goja a very cool and powerful languages. And you need to choose what suits you best for the task you are working on.
from expr.
thx so much for the comprehensive explanation.
just curious, i was looking at making my own cloudflare workers (which would prefer js than wasm), so was wondering if i can use expr as replacement?
i know expr is not using js but i was wondering will it be a good fit for FaaS kind of scenario,
also i'm hoping able to do "hot reload" like detecting file changes and reload expr lang script. <- any caveats? for example i wont use "golang plugin" reload as memory is not reclaimed for the old unused golang plugins.
will expr be a good fit for FaaS? what caveats do i have to look out for?
@antonmedv appreciate this last question. thx. will use expr in filtering too.
from expr.
Related Issues (20)
- Constant 1 overflows int64 when compiling expressions with int64 type parameters HOT 2
- Feature request: UNKNOWN type HOT 6
- Feature request:two builtin array functions HOT 2
- it is really fast. question on language compatibility issue... HOT 2
- Add `flatten()` builtin HOT 3
- how to implement the 'like' bool expression using expr HOT 1
- Add better documentation about `min` `max` builtins
- invalid char escape HOT 1
- *vm.Program Not Safe HOT 1
- Support matches for bytes HOT 1
- Question: Is there planned support for iterator in version 1.23? HOT 6
- pass nil to interface method get runtime error "Call using interface {} as type *int (1:5)"
- expr.AsKind not work? HOT 4
- Language support for VSCode? HOT 5
- Double definition of Variable/Function not usable anymore. HOT 2
- Cannot use map[string]interface {} as argument (type main.Env) to call dump HOT 5
- Functions defined on the struct are bidden to the Env they were compiled with HOT 6
- Create custom function with many arguments HOT 1
- Feature request: allow multiple expressions in a single program HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expr.