-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rethink 'with' naming pattern for constructors? #140
Comments
I think your suggestion in Slack to use I think it would be ideal if I could write "ModuleName.from" and have my editor be able to list all the constructors for that type. Right now, sometimes it's |
Never mentioned piping, I mentioned partial application 🙂 Piping is one use of partial application, but I think it can also be useful when doing things like mapping over Your point is well taken, though - looking through my code, I think most uses of Ooh, and I do really like these somewhat-weird constructors, I use them quite a bit: Vector2d.from : Point2d units coordinates -> Point2d units coordinates -> Vector2d units coordinates
Vector3d.from : Point3d units coordinates -> Point3d units coordinates -> Vector3d units coordinates
LineSegment2d.from : Point2d units coordinates -> Point2d units coordinates -> LineSegment2d units coordinates
LineSegment3d.from : Point3d units coordinates -> Point3d units coordinates -> LineSegment3d units coordinates
Arc2d.from : Point2d units coordinates -> Point2d units coordinates -> Angle -> Arc2d units coordinates I guess those still count as "starting with |
A couple questions/thoughts (partially just thinking to myself here, but happy to take suggestions):
|
To me Not sure what I think about the rest. Lots of tricky decisions! I think the |
Could also just rename |
Yeah, for me |
Several
elm-geometry
constructors use a similar naming pattern usingwith
as part of the name, e.g.:These are reasonably concise (e.g. compare
Vector2d.withLength
toVector2d.fromLengthAndDirection
) and work well with partial application; for example, you can create a bunch of circles with the same radius at different points usingHowever, there are some downsides:
Vector2d.withLength
sounds like it might take an existingVector2d
and adjust it to have the given lengthwith
keyword has specific meanings in other programming languages, such as referring to resource handling/cleanup in Python, which may be confusingFor 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.The text was updated successfully, but these errors were encountered: