Skip to content
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

Consider immutable objects for a new version? #10

Closed
robations opened this issue May 27, 2016 · 1 comment
Closed

Consider immutable objects for a new version? #10

robations opened this issue May 27, 2016 · 1 comment

Comments

@robations
Copy link

This library is very useful but I think the interface could be improved a little.

Say you have an instance of LatLng, if you call any method ->toXyz() the common expectation is to return an object/value in whatever the new format is. You wouldn't necessarily expect the original object to change. The problems are that now we have an object that can be in different states and it is hard to track what state that object is in, and so much easier to make errors. Compare toWGS84() with toOSRef() which does return a new object.

There is also potential confusion if you don't know how this is implemented. What happens if you call $latLng->toWGS84(); $latLng->toWGS84()? You have to look in the code to work out that this is safe.

Also, calling any of the methods toOSRef(), toUTMRef() and toITMRef() (while returning a new object) has the side-effect of converting the current object to another ellipsoid, and this is another potential source of bugs. There is nothing in the API to warn about this.

The PHP DateTime class went through a similar pain, PHP rather late in the day came out with DateTimeImmutable, after realising that working with mutable value objects can be clumsy. I think easier for me to link to something that explains better [or Google cache because main site seems to be down].

@dvdoug dvdoug closed this as completed in e499db6 Jun 1, 2018
@robations
Copy link
Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant