Sometimes I wonder why people try to solve problems with inappropriate tools, and this is just an example:
There is another programming language which is much better fitted to the problem domain of constraints: Prolog. In Prolog, constraints are simply expressed as predicates (a natural fit) and the computer will then find a solution all by itself.
So the essential difference to Java is that in Prolog you tell the computer how a solution looks like, rather than how to get to it. The computer will then find a solution that matches all constraints automatically.
Why this matters? Because a Prolog program would only take a tenth of the Java code to solve problems like this. And because you don't need to think about how to tell the computer to find a solution, you can entirely focus on the problem domain and refine your constraints.
I'm not saying that Prolog is better than Java. I'm saying that one should think first which tool is best suited to the problem domain. In case of constraints, Prolog is first choice and Java is a poor mans choice.
BTW: Choosing the right tool for the job doesn't necessarily need to mean one way or the other: With SWI-Prolog you can call Prolog from Java and vice versa.
Regards, Christian |