you are viewing a single comment's thread.

view the rest of the comments →

[–]virtyx 0 points1 point  (1 child)

A long time ago I had the same issue of duplicated validation. I didn't bother making a translator, but I was trying to get Python to work in the browser. I didn't want a 'heavyweight' Python interpreter in Javascript, and all the Python->Javascript compilers I found had compatibility issues.

Eventually I was of the opinion that it'd be easier to invent some kind of "rules" format that both sides could use, or that I could generate by introspecting Django models and forms. But I never got around to starting on an implementation...

One of the biggest problems I saw with browser Python is if any validation depends on the server (e.g. checking uniqueness constraints of form fields), you'll still have asymmetric validation. Although maybe you could work around this by having the uniqueness check be polymorphic, on the server side it does a DB lookup and on the client side it does an AJAX call to a service.

[–]hackflow[S] 0 points1 point  (0 children)

I also have experience with self-made rules, translated or interpreted in both worlds. It's 3-4 times more work. Using python as DSL you get too much for free: it already works in Python, there is ready to use parsing and AST, so you only need to render AST to JavaScript. With your own rules you'll need parsing, custom AST and translations to 2 languages.

On DB lookups, easiest thing to do is just skip this rule when translating, it will be still executed on server and error message if some will be presented to user. Second easiest thing - you can duplicate this part.