Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming Language independent Model Validation

Let's say you use several different programming languages and frameworks in your infrastructure to handle large amounts of traffic etc.

Example Stack:

  1. event driven API servers (using Scala, node.js, Ruby EM)
  2. a standard full stack webapp (e.g. Rails)
  3. (maybe more technologies)

When using different languages and frameworks I usually end up duplicating most of the model validations because every "customer entry point" needs to validate its input. This is of course a pain to keep in sync.

How would you handle this without something like CORBA?

like image 978
Roland Avatar asked Mar 11 '11 21:03

Roland


People also ask

Which language is used for validation?

JavaScript is used to validate the form.

What is language-independent in programming?

A language-independent specification (LIS) is a programming language specification providing a common interface usable for defining semantics applicable toward arbitrary language bindings.

What is language-independent interface?

IDLs describe an interface in a language-independent way, enabling communication between software components that do not share one language, for example, between those written in C++ and those written in Java. IDLs are commonly used in remote procedure call software.


1 Answers

Your best bet would be a framework that allows you to specify model validation in a language agnostic format, like JSON. You might end up with a validation schema of sorts, say:

{
  "name": [
    {
      "validate": "length",
      "minLength": 6,
      "maxLength": 10
    },
    ...
  ],
  ...
}

You would then have language-specific validators that could parse this format. The validators only need to be written once, and then you maintain a single schema for each model.

However, this is probably sounding a lot like CORBA/SOAP/Thrift/ProtocolBuffers/etc. at this point. That's because they were written to solve these types of problems, and you'll end up reinventing a few wheels if you write it yourself.

like image 171
Nathan Ostgard Avatar answered Sep 28 '22 11:09

Nathan Ostgard