I'd have to agree with Abigail-II on this one. Provided that you are unlikely to move to a DMBS that doesn't support stored procedures any time soon, SPs are as fundemental to decoupling your applications from the database schema, as assessor/mutator methods are to decoupling your objects from their underlying implementation.

They are also the DBMS equivalent of using perls builtin functions in terms of performance. Just as the most efficient way of processing data in perl is to, as far as possible, minimise crossing the boundaries between the interpreted byte-code of your program and the compiled C of the built in functions, so minimising the frequency (and volumes of data, but that isn't always possible) crossing the boundary between your application and the DB is the most effective way of using the DB.

Applications, especially business applications, shouldn't be concerned with how to get the information they need, ie. which tables, how to build the SQL queries etc. They should only need to ask for 'the lastest orders to be processed', or the 'Delivery details for order number nnnnnnn'. Using stored procedures is the best way of isolating the application from these details, especially if there are multiple applications that use each type of business object. If the schema has to change, all the changes are isolated with the DBMS, provided that the SP name and the data required by the application stays the same. I've also used SPs to allow the same application to talk to several DBMSs.

Sure, SPs can be badly written but so can Perl and SQL. Especially SQL! The vast majority of people using SQL have no idea of the costs of using JOINS, referential integrity, foriegn keys, badly chosen primary and secondary indexes. And even if you become expert enough in any given DB to understand these costs. Move to another DB and your knowledge may well be useless.

That's why really good DBA's are way more than just people that ensure the backups are done. Also why a good DBA becomes a specialist in the DMBS that he deals with. Unfortunately the ideal of SQL as a write once, run anywhere database selection and administration language is forlorn.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

In reply to Re: Re: Re: N-tier, client/model, and business rules? by BrowserUk
in thread N-tier, model/view, and business rules? by LameNerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.