[Business-]Apps of the future? An idea to cross-platform logic

A proven method

What has often been done and implemented in various ways is something like this:

  • The actual apps people are working with are basically thin-clients.
  • The apps interpret some simple declarative language that describes the UI.
  • For all actions/choices etc. they call out to some central server.
view:
elements:
- type: title
label: Purchase order
- type: textfield
id: product
label: Article
- type: textfield
id: amount
label: Amount
- type: button
id: submit
label: Place order
action: /api/businessclient/order/new
UI rendered from declarative description

Limitations

While this works great for simple cases it has some downsides:

  • Needs to call the server for every action to get the reaction.
  • Any kind of logic that should be evaluated on the client has to be either hard-coded on the client (NO) or you have to come up with new declarative elements (see below)
view:
elements:
...
actions:
- type: flashscreen
for: 1000
- type: beep
times: 2
  • If you start going down the declarative actions route you need to implement them in every client-implementation you have.
  • If you want more dynamic behavior you probably end up with actions that take lots of parameters and/or trying to specify certain relationships between elements in a declarative way

The idea

Some time ago I realized that today almost all platforms have JavaScript engines by now:

view:
elements:
...
- type: textfield
id: product
...
script: >
function onProductExit() {
if (!model.getValue('product')) {
util.log('product field must be filled');
ui.setFocus('product');
}
}
“on” + capitalize(fieldName) + “Exit”
  • Write once, run anywhere ;)
  • Testing: you can run the script parts of the client code with automated tests on the server.

Looking for the problem

As mentioned in the beginning, I’ve “pitched” this idea to a few people by now, and I’ve shown a demo in a session at the SoCraTes Day Linz 2016.

  • ReactNative / NativeScript: these already allow you to build client-code in JavaScript and have it run in a native shell application. You can even exchange basically the whole app by providing new scripts/resource from a server.
  • HTML/Hybrid apps: most modern mobile ecosystems have pretty strong browser-engines as well, so if you are able to build all your code in HTML+JS you have an extremely flexible solution. Even if you need access to the phones APIs, there are other technologies that allow you to do that (Apache Cordova, …)
  • Sometimes hybrid apps are just not acceptable/desired. And maybe you/the client is skeptical of technologies like ReactNative etc. The argument may be: exposing an object with 5–10 callbacks to a JavaScript engine is easy and will be easy in 5 years also, supporting a ReactNative app may no longer be easy by then.
  • You may consider that code to be part of the business-logic (e.g. a certain field must match a very specific criteria) so keeping it close to your business logic and testing it in together with the rest of it sounds reasonable. At least I’d prefer that to having parts of it suddenly in some completely separate client-project.
  • Using it only to share some logic, without any generic UI. Especially useful for small algorithms that you want to be able to iterate on quickly and use on Android & iOS clients. One example that was brought up is: deciding when to show “Do you want to rate this app?”-dialogs to the user. The product-team may want to try out new, more complex combinations of conditions when to show this dialog, but you’re not able to release a new client version every week (especially on iOS).
  • Just for client-side validation. This could be useful if you want to share client-side validation code between a web-app, Android & iOS clients.

--

--

Software engineer from Austria. Passionate about software, likes photography, addicted to podcasts and always busy. http://paukl.at

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Paul Klingelhuber

Paul Klingelhuber

81 Followers

Software engineer from Austria. Passionate about software, likes photography, addicted to podcasts and always busy. http://paukl.at