programmingbitcoin
programmingbitcoin copied to clipboard
Chapter 2 - Coding One More Exception - why include self.x in the test of self.y == 0?
In the last 'special case' added to Point.add at the end of Chapter 2, the explanation and note list the criteria for this case as "If the two points are equal and the y coordinate is 0" which could be tested using the code:
if self == other and self.y == 0:
However the code in the sample includes an unnecessary multiply by self.x, here's the code:
if self == other and self.y == 0 * self.x:
Am I right in assuming that * self.x was included in error (and should therefore simply be removed).
P.S. Thanks for writing the book - I'm enjoying it!
Thinking a little more (and after reading chapter 3!) is this extra term required when we start to use Point together with operators for number systems other than 'real' (e.g. with FieldElement)? If so (which seems likely), some sort of note referring to the apparent pointless nature of the clause 'at the moment' in Chapter 2 - and a later note on the requirement for this in Chapter 3 would seem (to me) to be required.
Even then, however, some justification for this clause in Chapter 2 is really required (again IMHO).
I'm not caught up to you, but I had the exact same thoughts, @bernardfitch . I thought it might be some catch for where something is awry with self.x, initially thinking it was to catch self.x == None and thus None * 0 would fail... but that's dealt with above already. I figured it must have a meaning, but also spend a bunch of time wondering why, potentially just overthinking this!