3 ms·
Wouldn't it make more sense to make `point` a factory method on instances of curves?
by dkarapetyan 9y ago
Wouldn't it make more sense to make `point` a factory method on instances of curves?
- j2kun 9y agoPersonally, I have always found these patterns make more sense in a large-scale engineering context (to avoid others misusing a library) than a primer whose goal is to teach one about math. I don't think anyone would realistically use this code for a production application (it's quite slow, and vulnerable to certain timing attacks anyway)
- Cogito 9y agoWhile dkarapetyan used the term factory, which awakes deep rooted emotions in anyone who learned Java at university, the point is not really one of using a pattern or not (even though the pattern may make sense here). If you have a curve already, it makes sense to get one of its points. Having a method on the curve class that gives you a point would be just as easy, if not easier, than creating the point and passing in a reference to the curve. The reason you might use a factory is because we have different kinds of points being returned (Point and Ideal) - why not use a factory do return the correct one? The reason of course, which may not be obvious, is that these are points in a projective space and the ideal point doesn't have an (x,y) representation. (x,y) really means [x:y:1] and the ideal point is [0:1:0]. So using a `factory` is not necessary, as you know when you are creating the point what type it will be (either Point or Ideal) - there is no case where you would get the Ideal and not already know that it is the Ideal (at the point of object creation, that is).