0

I find this class definition a bit odd: http://www.extremeoptimization.com/Documentation/Reference/Extreme.Mathematics.LinearAlgebra.SingleLeastSquaresSolver_Members.aspx

The Solve method does have a return value but would not need to because the result is also available in the Solution property.

This is what I see as traditional code:

var sqrt2 = Math.Sqrt(2)

This would be an alternative in the same spirit as the solver in the link:

var sqrtCalculator = new SqrtCalculator();
sqrtCalculator.Parameter = 2;
sqrtCalculator.Run();
var sqrt2 = sqrtCalculator.Result;

What are the pros and cons besides the second version being a bit "untraditional"?

Yes, the compiler won't help the user who forgot to assign some property (parameter) BUT this is the case with all components that contain writeable properties and don't have mandatory values in the constructor.

Yes, threading will not work, BUT each thread can create its own solver.

Yes, the garbage collector won't be able to dispose the solver's result, BUT if the entire solver is disposed it will.

Yes, compilers and processors have special treatment of parameters and return values which makes them fast, BUT the time for parameter handling is mostly neglectable.

And so on. Other ideas?

Johan Nilsson
  • 427
  • 4
  • 10
  • "PM": Your edit http://stackoverflow.com/review/suggested-edits/3088745 was rejected. Consider posting it as a separate answer or as a comment. Substantial modifications which change the meaning of the answer are usually rejected. – Athari Oct 08 '13 at 11:18

1 Answers1

0

Well, after a year I found a clear flaw with this "introvert" approach. I am using an existing filter object which should operate on a measurement object but rather operates on itself in a "it's all me and nothing else"-fashion described above. Now the customer wants a recalculation of a measurement object a few minutes after the first calculation, and meanwhile the filter has processed other measurement objects. If it had been stateless and stored its data in the measurement object, it would have been an easy matter to implement a Recalculate method. The only way to solve the problem with an introvert filter is to let a filter instance be a part of the measurement object. Then filters need to be instantiated for every new measurement object. And since filters are a part of a chain the entire chain needs to be recreated. Well, there is some merit to being stateless.

Johan Nilsson
  • 427
  • 4
  • 10