Mikkel Ravn
Feb 23, 2017 · 1 min read

I’m happy you found the article useful! I wouldn’t implement lerp using a factory constructor. Three reasons:

  • It breaks with a Flutter SDK convention.
  • It forces you to type new whenever you use it.
  • More importantly, there are cases where you need to return null from lerp, for example if both begin and end are null. I’ll return to the meaning of this in part two; suffice it to say that Color.lerp interprets a null end-point as a completely transparent color, and returns null when both end-points are null. Factory constructors allow returning null, but it doesn’t strike me as a particularly good practice. Maybe I’m just still too much of a Java guy, but an expression like new Bar.lerp(...) screams “not null” to me. Bar.lerp(...) does not.

Thanks again for reading and commenting.

    Mikkel Ravn

    Written by

    CTO, founder at Raven biosciences. Software developer and architect, formerly at Google, QIAGEN, CLC bio, Systematic, U Aarhus. PhD in computer science 2003.