Tag Info

Hot answers tagged

108

Tackling the if web problem you can create a rule engine where each specific rule is coded independently. A further refinement for this would be to create a domain specific language (DSL) to create the rules, however a DSL alone only displaces the problem from one code base (main) to another (DSL). Without structure the DSL will not fare any better than ...


80

It sounds like all these conditional statements that you're talking about should really be data that configures your program rather than part of your program itself. If you can treat them that way, then you'll be free to modify the way your program works by just changing its configuration instead of having to modify your code and recompile every time you ...


38

No one has mentioned this, so I thought I'd say it explicitly: Thousands of "If .. Then .. Else" rules is a sign of a badly designed application. While the domain specific data representation might look like these rules, are you absolutely certain that your implementation should resemble the domain specific representation?


34

The logic programming language Prolog may be what you're looking for. Your problem statement is not specific enough for me to assess if it's a good fit but it's rather similar to what you say. A Prolog program consists of facts and rules that are applied. Here's a simple example rule that states "A cow moves to a location if the cow is hungry and there is ...


26

Based on what you describe, you're probably going to want to explore the wonderful world of databases. It sounds like many of the magic numbers you describe - particularly if they are part dependent - are really data, not code. You'll have much better luck, and find it far easier to extend the application in the long run, if you can categorize how the data ...


18

I have seen it. Didn't end up well. I think that cucumber is cumbersome (<--lol :D) abstraction for this exact reason. Too hard for non-technical people to write by themselves; too verbose for technical people. Non technical people just haven't learned to think like programmers. It is our privilege to understand abstract knowledge, break it down, ...


18

Business logic doesn't go into the database If we're talking about multi-tier applications, it seems pretty clear that business logic, the kind of intelligence that runs a particular enterprise, belongs in the Business Logic Layer, not in the Data Access Layer. Databases do a few things really well: They store and retrieve data They establish and enforce ...


14

Unless you anticipate extending this to multiple parts I'd be reluctant to add a database just yet. Having a database means a big pile of stuff to learn for you, and more stuff to install to get it to work for other people. Adding an embedded database keeps the final executable portable, but someone with your source code now has one more thing to get ...


13

Rules engines might help because if there are so many if/then rules it might be helpful to get them all in one place outside the program where users can edit them without needing to know a programming language. Also, visualization tools might be available. You could also look at logic programming solutions (like Prolog). You can quickly modify the list ...


12

If you mean representing individual business rule checks with exceptions, then I don't think it's a very good idea. Many times you have to report more than one failed condition, and not stop on the first one. On the other hand, I do believe that checking for all rules and then throwing an exception with the summary is a good practice.


12

Please, use software/computer languages that are fit for the task. Matlab is used very often to model complex systems, where you can have indeed literally thousands of conditions. Not using if/then/else clauses, but by numerical analysis. R is an open source computer language that is filled with tools and packages to do the same. But this means you also have ...


11

Exceptions to business rules are generally not exceptions -- they are almost always simply more rules. So, the first thing I'd do in this case is ask WHY this particular record is an A but gets treated as a B. Where and how is that decision recorded? If the answer is that it's recorded outside of the data that your process has access to, then the ...


10

It's suddenly dawned on me: You need to use a Decision Learning Tree (ID3 Algorithm). Its highly likely that's someone has implemented it in your language. If not you could port an existing library


10

3. Build an override option into the program, where you can (optionally) explicitly specify a rule set for a certain processing job instead of having the program decide automatically.


9

This is one of the use cases for BDD frameworks, like Cucumber, that allow you to capture the business requirements in code and test against those requirements frequently. Other approaches I've seen used include long and complicated specification documents, large sheets of paper tacked to the wall, slide decks, and Joe, the guy at the end of the table who ...


8

Every large application contains thousands of if-then-else statements, not counting other flow controls, and those applications are still debugged and maintained, despite their complexity. Also, the number of statements does not make the flow unpredictable. Asynchronous programming does. If you use deterministic algorithms synchronously, you'll have a 100% ...


8

In the example you've given us I think that raising an exception is a bad idea. If you know that the user is not authorized before they start working and you still allow them to do some function and then smack them with an message AFTER they've already completed the task, that's just a bad design. Using exceptions to enforce business rules is not a good ...


8

This is more of a community wiki answer, aggregating the various modelling tools suggested by other answers, I've just added additional links to resources. I don't think there's any need to restate that you should be using a different approach to thousands of hard-coded if/else statements. DSL Programming (Domain Specific Language) Markov Model/Markov ...


8

Part of the difficulty in terms of the customer writing a specifications document is that the customer often doesn't know how to translate the things the customer wants into a language which actually describes what the customer needs. While the customer may say that they want a certain behaviour to exist in a system, they are generally not so concerned with ...


8

What you’re asking for is essentially a domain-specific language—a small programming language for a narrow purpose, in this case defining P&P RPG rules. Designing a language is in principle not difficult, but there is a considerable amount of up-front knowledge that you must gain in order to be at all productive. Unfortunately, there is no central ...


7

I would use WF or Drools if you're trying to create an abstraction that non-programmers could work with to develop business rules. However, if you're dealing with programmers than the abstraction of WF isn't worth the time it takes to develop a solution, I fail to see the added value for your investment. A database is a good way to maintain rules that ...


6

We've had basically the same experience where I work and we've addressed it by having a OrderBusinessLogic class. For the most part the layout you've described works for the majority of our business. It's nice and clean and simple. But on those occaisions where you have buy any 2 from this category, we treat that as an "business execption" and have the ...


5

I don't see what value throwing an Exception has in creating good business logic. There are dozens of approaches to handling business logic that do not involve using a system that is meant for addressing unexpected conditions in the operation of a system. It is expected that in business logic, conditions will not be met; that's the reason for having it in ...


5

If you consider that a Customer is a part of the domain model, then it makes sense (especially within the context of DDD but not limited to it) to have have both properties and operations for that object. With that said, however, I think that the example you've used is a poor one, and is a cause of the argument. If you're talking about persistence, then ...


5

I would focus on use-cases and user-stories. I could document them, perhaps in a wiki, and give each one an ID (like UC00001). Then when I wrote unit tests and/or integration tests, I'd label them with the use case they inform. Then when I get to two unit tests that can't both pass because they're mutually exclusive, I'd throw those two use cases back at ...


4

The decision as to whether to expose an interface for non-technical personnel to modify business rules largely depends on several factors, including the goals of the project, cost of the project, lifetime of the project, and the ratio of knowns to unknowns in the project. For instance, if I believed that no one would use the rules interface, then I would ...


4

If you are guaranteed that there will be exactly one of of the "special" records and that it can be identified easily (i.e., by its id in your example), option 1 is just fine. Don't hard-code the record ID into the program; accept an optional value from the command line or whatever way your environment lets you specify these things: % process-records ...


4

You may look for different simple rule engines in .NET. However, in the case if you're using .NET 3.0 or later, you can use the Rules Engine of Windows Workflow Foundation without using actually Workflow. We have done this in our project, and you are free to use SQL or XML as the back-end, and it works pretty good. You can use the IDE that comes with the ...


4

No matter whether you write the rules in PHP, JavaScript or some other, possibly domain-specific language. If the requirements are sufficiently complex (yours seem to be), they will require something with expressiveness of programming language and will require programming skill to update. Forget business people updating them, they don't have the necessary ...


4

I used to work with magento, which was an e-commerce platform (in php-mysql) that was doing exactly that. There is too-much effort for doing the functionality you want from scratch, so integrating an off-the-shelf solution might be more appropriate. From the answer above: "Forget business people updating them, they don't have the necessary skill." This is ...



Only top voted, non community-wiki answers of a minimum length are eligible