7

Doesn't it seem relatively duplicative to define your Models in your backend code AND on your front end for a rich internet application?

I'm porting a GUI application I had written to have a web interface, which is all grand and nice any all, but things like Spine, SproutCore, JavascriptMVC would have you define your models and views and implement specific controllers.

Being that I've got a well defined MVC pattern on my backend code (which is making this super easy to port; the views in my app took python dicts and returned python dicts to the controllers which could easy interface with the models; I can just convert these to JSON back and forth to speak to the web front end), why would I want to recreate the entire pattern again on the front end?

What are good ways to work around this?

Should I just say "screw this" and use something like http://pyjs.org? Should I write a bunch of code to export my models into JSON and then write some JavaScript code to build the Models on the front-end automatically so I'm still only defining them once?

What would be the best approach to this?

14
  • 1
    Just use node.js on the back end and power through with 100% code re-use.
    – Raynos
    Dec 30, 2011 at 17:49
  • I've already got my backend developed in Python. Also nodejs still doesn't provide a generic ORM module like SQLObject. My data model is portable across ANY database that SQLObject supports without modification. I like this model since I can start (or even do local dev) on SQLite and if I need better performance/functionality I can switch to a bigger DB system (mysql, postgres, etc) by changing a line in my configuration file. And the app I'm building does not benefit from a NoSQL solution, so that's not the answer here.
    – tkone
    Dec 30, 2011 at 17:54
  • there are various ORM tools that are good enough. The fact you can 'port' data between SQL databases is not an advantage. It means your using the dumb subset of all database and are simply just not using your database at all. I also dont see how running mysql or postgres locally is a problem. Unless your developing on a netbook
    – Raynos
    Dec 30, 2011 at 19:12
  • Why don't you develop your website with server-side Python? Developing sites entirely in JS doesn't have many advantages...
    – alex
    Dec 30, 2011 at 20:59
  • @Raynos "good enough" should never be acceptable. It's not that you're using the LCD functionality of the underlying DB, rather the ORM replicates functionality or relegates it to the database itself. With a real ORM there should be no disadvantages over using the ORM versus writing your own SQL queries; that's why you use a proper ORM. Plus if all else fails and the ORM can't cut it, you still can communicate via good old db-specific SQL via the ORM which will at least manage connection pooling, escaping queries, etc. Also "your" would denote ownership. "you're" is what you wanted.
    – tkone
    Dec 31, 2011 at 1:39

1 Answer 1

1

I had a similar question / problem, for me, knockout.js and their mapping plugin worked:

http://knockoutjs.com/documentation/plugins-mapping.html

https://stackoverflow.com/questions/6796909/is-there-a-native-way-to-create-client-side-models-to-post-to-my-controllers-wit

1
  • I didn't see this answer until just now. Will have to investigate. I do backbone for work now, so I'm inclined to use that, throw away my back end and just make a python rest client to communicate to a document store -- therefore the model is defined by the backbone model. It changes, cool, as old docs are loaded they'll change to the new format as well.
    – tkone
    Feb 29, 2012 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.