Hot answers tagged

17

Is scientific code a different enough realm to ignore common coding standards? No, it's not. Research code is often "throw away" and written by people who are not developers by background, however strong their academic credentials. Some of the research code I wrote would make current me cry. But it worked! One thing to consider is the gatekeepers to ...


15

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

Genetic Algorithms and Neural Networks are not suitable here. They are meta-heuristics for finding a good-enough, approximate solution to a problem. Notably, both require you to find a cost function to rate candidate solutions. Once you have such a cost function, it might be easier to manually come up with an algorithm that optimizes for this cost. This is ...


11

Scientists are not developers. Their job is not to write code per se. Their job is to solve problems, and programming is just one of the tools they may use. Most enterprise code written by—as they would call themselves—professional developers is a mess. Most of this code doesn't use design patterns or misuse them. Most comments are candidates for ...


10

You can use simulated annealing. I did something like that before I landed my first job - see https://vimeo.com/20610875 (demo starting at 2:50, algorithm explained from 6:15). Simulated annealing is a type of a genetic algorithm, and maybe it was not suitable in theory (as @amon maintains in his answer), but it worked very well in practice, and it was ...


9

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


9

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


7

Consider General Game Playing. The idea is to write a program that performs well playing any game that can be formally described. So you don't create a tic-tac-toe program or checkers program or Reversi program. You create a program/agent that can play all of these games with the best general performance. The steps of a GGP session are: The game server ...


6

Based on what you've said in comments, this is how I would handle it: Implement the story as a finite state machine, with a twist. Each State is a page of the story, and each Transition is a link from one page to another. But each Transition also has Conditions. The Conditions could be null, in which case the Transition always shows up as an available ...


6

Genetics Algorithms do apply here. During my undergraduate program, one of my colleagues wrote a paper to very similar problem of yours. You can look for Job Shop Scheduling and also Open Shop Scheduling or Flow Shop Scheduling can be interesting starting points To use a genetic algorithm you don't need a perfect solution, you can start with N random ...


6

Ignore? No. Re-consider and adjust? Sure. A lot of scientific code is math intensive and performance critical. Things like the overhead of function calls can actually become a problem, so you may end up with more deeply nested structures then you see in a typical commercial app. That doesn't mean you should dive head first into a thousand ...


5

I think the answer is in the title: you need a rules engine. If you are planning to write your application with Java, you of course can write your own as Gilbert Le Blanc suggested, OR you might want to take a look at Drools, a rules engine. what options does a player have given the situation and his current state With Drools, or any other rules ...


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

Your latter strategy is likely the better choice. It will be difficult to find all the problems in the data while it is still resting in its current format. I would treat this an ETL process of sorts, combined with an iterative approach. Something like this: Build a beta version of the schema. Write a program to read the old data, scrub/transform it, and ...


5

Users do not like change. Even when the change is objectively superior from an UX perspective, the human resistance to change habits will result in them finding it subjectively worse. So when you already have a userbase you are developing the new application for, it is not a bad idea at all to follow the UI conventions they are used to instead of following ...


5

If the database is under control of the application (not modified by anything else), do it at the application level, not the database level. In theory you could do it with triggers, but I don't think you should. Checking the validity of such a structure requires computationally complex queries, and there is significant danger that this will have a ...


4

Well, all performance and redundancy considerations aside, unless .net database exceptions are more sophisticated than in every other language I've ever worked with, the simple fact of needing to construct an error message readable by non-programmers sort of necessitates the first method, unless you prefer error messages that read something like: Error ...


4

I come across this kind of requirement all the time. Let's say you have a date range you want to check (ie, find free units for) which is defined with a start and an end date. In the database, for the sake of making it clear what we're talking about, lets say existing reservations have a first and a last date (of the reservation). So there's six possible ...


3

In constraint satisfaction, propagation means to make explicit a truth condition that is already present in the problem, but only implicitly. For instance, if you have a variable that must be even, and another that has to be greater than 10, those are constraints on the two variables. Nothing else is known about the solution. However, if you have another ...


3

Given that you have already defined what a rule is, the corresponding data structure would be straightforward (pseudo-code): class Rule { Condition condition; ActionSet positiveActions, negativeActions } However, as you indicated by your reference to a ruleset, the interesting part of rule engines is the process of rule selection and their execution ...


2

expressing business rules is one thing, implementing them is another think about the user experience; if the user is not a salesperson, why give them a button that says 'create invoice' at all?


2

These guidelines/idioms are called Constrained Programming, which is not easy thing to do. It is used for modeling and solving combinatorial problems (NP-hard, NP-complete). I can recommend you one book - Principles of Constraint Programming. This book is one of the best books on the subject, but, still, after reading it you still won't be able to apply it ...


2

Well, how will you invoke this thing? I would assume it's something like this: for (auto rule: ruleset) { if (rule.matches(context)) { if (rule.execute() == Stop) break # so rules can stop early # else: default action is to continue } } So, you have an object with with two methods bool Rule::matches(Context const& ...


2

Conceptually, your game is straightforward. In psudeocode, it would look something like this: while not at end of adventure story display text get response Now, chaining all of the text together so it flows from one action to the next is the hard part. You could use a relational database. You could use a tree. It's a little hard to be more ...


2

I would suggest you try to go away using actual boolean expressions and figure out what actions or events you're doing to the "system" that you're developing. If you're using if-statements you might as well use a scripting language. Once upon a time I've created a DSL in JSON format that defined rules as actions or events instead of using boolean ...


2

There aren't any download or storage limits for your app (other than available space on the device, of course); if there were, they'd be mentioned in the iOS Data Storage Guidelines. However, you do need to consider how your data files will work with iCloud -- in particular, you should decide whether it's okay for the device to discard your downloaded data ...


2

This is why they used to recommend taking the Artificial Intelligence class. Back in the 1970s and 1980s, there was a HUMONGOUS amount of work done on Rule-Based Systems, mostly for Expert Systems work. That included huge amounts of work done on rules engines. A fair amount of this work found its way into undergraduate AI textbooks. Take a look at ...


2

I regularly use approach two. Downside is that tests require a database. Some will argue that depending on a database is not 'unit-testing'. Indeed. The problem with this critique is that it considers unit tests as the One Size Fits All. Clearly unit tests are not tailored to be used with foreign systems. That does not mean you should not rely on those ...


2

This is perfectly possible with triggers, and if you must ensure integrity at an application-independent level, this is possibly your best shot. From this example you can see that recursion is possible in POSTGRESQL stored procedures, so traversing the tree should not be too hard to be implemented. Of course, you may have to implement "AFTER INSERT", "AFTER ...



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