You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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].
The text was updated successfully, but these errors were encountered:
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. ComparetoWGS84()
withtoOSRef()
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()
andtoITMRef()
(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 withDateTimeImmutable
, 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].The text was updated successfully, but these errors were encountered: