[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Language wars...


You are correct, you don't have to use the ORM and you can break out of
it. But then why use it at all? It is reasonably simple (especially the
direction we are going) to just have a sane api that you don't have to
break out of.

Well, my point was that it's not really "breaking out". The Model bit of MVC just means package up the data access part and seperate it from the controller code. It's a conceptual thing, not something to break out of. Catalyst doesn't appear to particularly bind you to use a database (as far as I can see, although it's true that Rails does to a certain degree).

Why use it at all? Well because the framework does soooo much more than just give you database access. The whole point is to provide the whole framework for free and you only need to write small amounts of custom code.

Consider that the code for say, viewing a transaction becomes just


   Bunch of SP's to load the data

   TT code to display the transaction

   Load different transactions, check we get the right stuff
   Call render, check it displays some sensible data
   Check we can click the edit, delete, print buttons without error, etc
   Check we can't view the transaction without being logged in

Notice how easy it is to chuck in a bunch of test code which does unit testing of the model and also checks that all the controller code still works!

It really is very neat once you manage to get a complete MVC separation. In the case of a financial app with lots of business logic it's extra nice because it helps focus people's mind on getting the business rules correct first and rendering the stuff second. It's quite a lot easier to just write a test app which manipulates the database and arses around with it trying to break it. You just instantiate a couple of models, start calling functions on them, then check that the database still looks consistent - great for testing

Actually in Rails there is a bit of a backdoor here and there is a "console" application provided. This makes it very easy to do database maintenance by simply dropping into the console, typing


...then pick out a transaction, and start manipulating it:

a = Customer.find_by_name("bob").transactions(1)
print a.tax
print a.shipping_address

b = Customer.find_by_name("Kate").transactions.new

See how easy it is to get an interface into your code once you go down this route?!

In the latest Rails they added a neat twist and let you call a different render template based on how the request was phrased. So you basically prepare all the data for an invoice, then you can have the output in XML *or* HTML (or PDF, or PS, etc, etc). The addition of an XML input parser came next and now you can post to the "edit" action in *either* XML *or* HTML Form! This tiny bit of extra framework means that you can now very easily keep 95% the same code and yet largely support a REST interface to your whole application with very little code to change! Wow - cool.

This is the power of separating the framework from the application in my opinion. So really it should be written FMVC, and the code separated accordingly

But to be clear, I am NOT advocating that SMB needs use Catalyst. I just want to re-iterate that if you haven't at least written a short test application in one of the new MVC frameworks then you really are missing out on a lot of good *ideas*. It really doesn't matter (that much) whether it's Django, Catalyst, Rails, or whatever...

Good luck all

Ed W