The other day I attended a meetup with focus on sproutcore. Great introduction to the product with some very useful insight into how the framework was put together and how it should be utilized. What was cool about the whole meetup is I posted a photo from the AppNovation offices where the event was being hosted. I posted directly from my Android phone to Google+ with no effort (nice feature) and added a comment. The really cool part was the discussion that occurred between myself and two guys I worked with on a really innovative client-server C++ / Sybase SQL Server application 20 years back. Weird thing is we are all still coding in different capacities. Anyhow, the really interesting conversation was around the MVC pattern and business logic in the browser. We all agreed this was not the right way to go, and the sproutcore site was wrong in promoting business logic in the browser as a marketing message.
So why isn't business logic in the browser a good architecture?
Because pushing it out to the browser means it can no longer run on the server. Business logic can be reused for other services (think RESTful) where browsers are consumers of the logic (not the producers), business logic is intellectual property and shouldn't always be exposed in the browser, business logic often needs data and implements business decisions, this should stay on the server. Don't get me wrong a framework that supports HTML5 and implements the MVC pattern is a good architecture. Just pushing the business logic out to the browser is not good architecture. Now we may be getting into the definition of business logic, and if the Model within the MVC is considered the business logic and is only responsible for acting as a proxy for the data and business decisions through a web service API like REST then we are good.
So what does this have to do with mobile devices and good architecture?
HTML5 and the MVC pattern are very good practices when developing on mobile devices. This is mostly because of HTML5's ability to target multiple devices and the MVC being a very mature and proven pattern. The issue then becomes how should the application be architected? I'd suggest the following practices;
- Use a HTML5 / MVC approach when building the User eXperience (UX)
- Keep the Model thin and it should act mostly as a proxy to the server hosted web services
- Build the server hosted services using a well thought out RESTful design, ensure these services could also be consumed by non-mobile devices
- Be mindful of which features are required for mobile and which are better implemented within a browser based portal (consider the difference between the Google+ mobile app and the Google+ browser portal)
- Separate the database reads from the writes within the RESTful API (this will greatly help scalability)