Misfittech / nano_stepper

Stepper feedback controller
423 stars 179 forks source link

Detailed C++ programming questions #23

Closed tobbelobb closed 4 years ago

tobbelobb commented 6 years ago

Hello!

I'm just learning OOP and C++, and use this repo for practice.

First, I noticed a copy constructor that seems to do exactly the same as the implicit copy constructor. https://github.com/Misfittech/nano_stepper/blob/5c4fd1bcf080d8b54497ce33e1f1b736a181eeae/firmware/stepper_nano_zero/angle.h#L34

Are there advantages of defining this copy constructor explicitly?

I also noticed an operator overload for subtraction between angles. https://github.com/Misfittech/nano_stepper/blob/5c4fd1bcf080d8b54497ce33e1f1b736a181eeae/firmware/stepper_nano_zero/angle.h#L36

I was curious about what behaviour you wanted to change/control, so I compared the new minus operator with the shorter:

int16_t minus(const Angle &a2)
{
  return (int16_t)(angle - a2.angle);
}

... but no pair of input angles gave (a - b) != a.minus(b).

Is the explicit wrap condition in the minus-operator code there simply to make the code still work if ANGLE_STEPS ever changes?

Thanks for your software and for your time.

coolio986 commented 4 years ago

Programmer preference. Outside of scope.