29

A dev team has been spending the past couple of weeks working on a 'generic rule engine' to validate a marketing process. The “Buy 5, get 10% off” kind of promotions.

The UI has all the great bits, drop-downs, various data lookups, etc etc..

What the dev is storing the database is the actual string representation FieldA=“Buy 5, get 10% off” that is “built” from the UI.

Might be OK, but now they want to apply that string to an actual order. Extract ‘5’, the word ‘Buy’ to apply to the purchase quantity rule, ‘10%’ and the word ‘off’ to subtract from the total.

Dev asked me:

Dev: “How can I use reflection to parse the string and determine what are integers, decimals, and percents?”
Me: “That sounds complicated. Why would you do that?”
Dev: “It’s only a string. Parsing it was easy. First we need to know how to extract numbers and be able to compare them.”
Me: “I’ve seen the data structures, wouldn’t it be easier to serialize the objects to JSON and store the string in the database? When you deserialize, you won’t have to parse or do any kind of reflection. You should try to keep the rule behavior as simple as possible. Developing your own tokenizer that relies on reflection and hoping the UI doesn’t change isn’t going to be reliable.”
Dev: “Tokens!...yea…tokens…that’s what we want. I’ll come up with a tokenizing algorithm that can utilize recursion and reflection to extract all the comparable data structures.”
Me: “Wow…uh…no, don’t do that. The UI already has to map the data, just make it easy on yourself and serialize that object. It’s like one line of code to serialize and deserialize.”
Dev: “I don’t know…sounds like magic. Using tokens seems like the more straightforward O-O approach. Thanks anyway.”

I probably getting too old to keep up with these kids, I have no idea what the frack he was talking about. Not sure if they are too smart or I’m too stupid/lazy. Either way, I keeping my name as far away from that project as possible.

Comments
  • 5
    Find the guy that thought that storing that as a string was a good idea (or even an idea worth having) and make sure he'll never see the light again
  • 0
    Oh, and that kid definitely didn't know what he was talking about either
  • 2
    Slap him. Listen to your fucking elders.

    This is no better than storing markup in a database. Or worse still, code in a database. Essentially Dev is doing an eval - any code associated will be tainted with this broken thinking.
  • 0
    @willol We store shipping restriction details as a serialized DTO (XML). For us, it works beautifully. DBAs had a fit trying to develop a workable schema that didn't involve joining 25 tables. The rule data is similar. In theory, once the rules are established, they probably won't change and the web site could cache the objects with zero impact to DB performance. What the devs (yes, more than one) are proposing is going to slam the database, execute crazy amount of LINQ, every time you add something to the shopping cart (or change anything).
    Its usually a week or two of finger pointing before they finally ask for help optimizing their code.
Add Comment