Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Migrating database field values rules from Perl code to DB

by dragonchild (Archbishop)
on Feb 12, 2007 at 17:20 UTC ( #599564=note: print w/replies, xml ) Need Help??


in reply to Re: Migrating database field values rules from Perl code to DB
in thread Migrating database field values rules from Perl code to DB

Any time you want to start putting application constraints into a database, you should stop thinking and just do the simplest thing possible. That will, most likely, not involve a database.

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
  • Comment on Re^2: Migrating database field values rules from Perl code to DB

Replies are listed 'Best First'.
Re^3: Migrating database field values rules from Perl code to DB
by ptum (Priest) on Feb 12, 2007 at 18:47 UTC

    I respectfully disagree with this assessment. While it is certainly true that you can overcomplicate your application for the next poor guy who has to maintain it by storing all kinds of application logic in a database, there are a couple of good reasons for storing allowable field values and other application configuration data in a database table or tables.

    Such reasons may include:

    • The entry field in question may appear in multiple locations throughout the application -- storing (and retrieving) constraints like this may save you from some ugly (and difficult to maintain) duplication of code.
    • You expect the allowable values for some of the fields to frequently change over time, and you'd like to avoid multiple trivial releases of your code.
    • Updating your code in production is fraught with red tape; in some corporate environments, database changes can often sneak under the wire, avoiding onerous (but unsophisticated) bureaucratic constraints.
    • You have a very large number of entry fields with a large number of similar attributes, and you want to simplify your application code.
    • You need to be able to re-configure your application on the fly in a distributed environment.

    I'm sure there are more reasons than this, but these are a few which come to mind, suggesting that the advice dragonchild offered above is not universally true.

      The entry field in question may appear in multiple locations throughout the application -- storing (and retrieving) constraints like this may save you from some ugly (and difficult to maintain) duplication of code.

      You have a very large number of entry fields with a large number of similar attributes, and you want to simplify your application code.

      This is what configuration files coupled with useful abstractions are for. This is not what a database is for.

      You expect the allowable values for some of the fields to frequently change over time, and you'd like to avoid multiple trivial releases of your code.

      Changing the allowable value of a field is NOT a trivial release. If you allow a value that goes over an edge case, then you have introduced dirty data. Dirty data is almost always impossible to get out.

      You need to be able to re-configure your application on the fly in a distributed environment.

      This is the ONLY relatively sane reason to put application logic into a database. And, there are much better ways of accomplishing the same thing. The only thing a database brings to the table is the centralization. Centralized datastores aren't necessarily a full-on RDBMS. For example, a simple DBM::Deep or BDB file on a NAS would be perfectly fine for things like this.

      And, I've saved the best for last ...

      Updating your code in production is fraught with red tape; in some corporate environments, database changes can often sneak under the wire, avoiding onerous (but unsophisticated) bureaucratic constraints.

      Allow me to rephrase: "Because my company actually respects change control, I will exploit a loophole in order to avoid actually managing my changes. Instead, I will unleash changes unto prod in a lone-cowboy fashion."

      Change control exists for a reason. Often, it's because you do NOT understand the ramifications of your changes. Furthermore, even if your bureaucracy should be avoided, you are breaking your application design. Assuming that this is a good plan, it is a consequence and not a reason. It's like saying "Eating a bowl of sugar is good for my health because it's better than eating a bowl of lard."


      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

        Hmmmm. I seem to have struck a nerve. I admit I sometimes fall prey to 'lone-cowboy' thinking; in my defense, this mindset has not been historically catastrophic to me in my environment. I understand that there are some environments where cowboy coding can produce severe consequences, sometimes felt by innocent bystanders. Your mileage may vary.

        This is what configuration files coupled with useful abstractions are for. This is not what a database is for.

        I'm not sure why you differentiate between configuration files and database storage. Who cares whether the configuration details are stored in a simple file or in an RDBMS? Please help me to understand the importance, in your mind, of this distinction.

        Changing the allowable value of a field is NOT a trivial release.

        I'm not sure why changing data entry rules are not a trivial release in your estimation. Suppose I currently do business in 27 states, and I add a 28th. Up until now, users couldn't select a particular state from a drop-down list, now they can. I make a change in the table of allowable states, and suddenly data rows start showing up with this value in my tables ... not a big deal. This seems trivial to me. Am I over-simplifying?

        Allow me to rephrase: "Because my company actually respects change control, I will exploit a loophole in order to avoid actually managing my changes. Instead, I will unleash changes unto prod in a lone-cowboy fashion."

        Your conclusion about my motives is uncharitable and not fully informed, but I'll provisionally accept the rebuke. I will point out, however, that few of us have the luxury of working in a perfect world. I work in a world where 'Change Control Freezes' are routine and where application updates in production are periodically and categorically denied, across the board of the organization. Since I (and my immediate management) find this nonsensical and not in the best interests of the company, I exploit loopholes, to get real work done in the real world. This doesn't mean I don't manage my changes, it just means that I don't manage them in the 'perfect world' way. Since my conduct technically conforms to corporate policy, I conclude that if I can abstract certain data rules into the database, then that constitutes an acceptable level of risk, since the rule loophole exists. It is sort of like finding a little-known legal deduction when filing your taxes, I think. Weaselly, yes. Wrong, no. :)

Re^3: Migrating database field values rules from Perl code to DB
by hossman (Prior) on Feb 12, 2007 at 21:02 UTC

    if the discussion is about putting code in your DB that apps should SELECT out and then run arbitrarily, I'd agree with you on moral grounds -- but there are lots of situations where the "data" for one application is "constraints" for another application.

    CMSs are a great example of applications where the person writing the application doesn't know what kinds of constraints the end user needs for their data, because the "content" is different for each installation -- so the "adminstrators" of the system enter the constraint data, and the "users" of the system enter the content that conforms to those constraints.

    Surely you wouldn't suggest that everyone who wants to install/maintain a complex application needs to write code to define how they wnat to allow others to use that application? you might rgue "that's what configuration files are for." but how is puting that information in a configuration file really any different then putting it in a database?

      That's an apples'n'oranges distinction. "administrators" of a CMS are users of that CMS. The developers are meeting their user requirements.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

        That's exactly my point. your comment: "Any time you want to start putting application constraints into a database, you should stop thinking and just do the simplest thing possible. That will, most likely, not involve a database." is too general, because it doesn't take into account the fact that in many, MANY, cases the constraints are data (to someone).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://599564]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2022-01-28 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (73 votes). Check out past polls.

    Notices?