Giter VIP home page Giter VIP logo

Comments (2)

antonmedv avatar antonmedv commented on August 11, 2024

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 predicates all(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 unwrap ExportTo.

  • 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.

sprappcom avatar sprappcom commented on August 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.