-
Notifications
You must be signed in to change notification settings - Fork 28
Rethink 'with' naming pattern for constructors? #140
Copy link
Copy link
Open
Labels
Description
Several elm-geometry constructors use a similar naming pattern using with as part of the name, e.g.:
Circle2d.withRadius : Quantity Float units -> Point2d units coordinates -> Circle2d units coordinates
Axis3d.withDirection : Direction3d coordinates -> Point3d units coordinates -> Axis3d units coordinates
Vector2d.withLength : Quantity Float units -> Direction2d coordinates -> Vector2d units coordinatesThese are reasonably concise (e.g. compare Vector2d.withLength to Vector2d.fromLengthAndDirection) and work well with partial application; for example, you can create a bunch of circles with the same radius at different points using
List.map (Circle2d.withRadius (Length.centimeters 5)) listOfPointsHowever, there are some downsides:
- As pointed out by @MartinSStewart, the names can sound more like 'modifiers' than 'constructors', e.g.
Vector2d.withLengthsounds like it might take an existingVector2dand adjust it to have the given length - The
withkeyword has specific meanings in other programming languages, such as referring to resource handling/cleanup in Python, which may be confusing
For the next major release of elm-geometry, it may be worth reconsidering this pattern and seeing if there's an alternative that is more clear.
Reactions are currently unavailable