Tag Info

Hot answers tagged

111

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 ...


40

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?


40

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 ...


20

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 ...


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, ...


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

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.


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 ...


13

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 ...


5

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 ...


5

I think it pretty much comes down to whether the uppercase-ness is a display requirement or a property of the data itself. To take a different example, if it was necessary to display a name with the surname uppercase for emphasis, I would capitalise it in the output UI, as in your (1). This is a display requirement as surnames are not 'naturally' uppercase ...


5

Within the context of the MVC pattern, the Controller and View components are only concerned with user interactions (the Controller with reacting to requests and the View with presenting the UI). All other code, including the business logic and database access goes in the Model component. As the Model is usually quite large, it should have an additional ...


4

Probably the most common form is Use Cases. You can supplement them with screen mock-ups and descriptions. A book I'd recommend is "Writing Effective Use Cases" by Alistair Cockburn. It describes how you can write use cases at various levels of detail, how to avoid falling for the 'template' driven approach, and just sticking to documenting the necessary ...


4

I began building an engine using WWF WCF several months ago. I do not know how complex your rule base is, but ours was pretty large. When you have the potential for something like 40,000 branches, WWF is not a good fit. As an alternative, I ended up building an engine that used logic exception tables in SQL. The rows would store the basic values, as well as ...



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