|
yeah, that`s what it comes down to, that`s the core doctrine.
|
|
|
|
|
Not whinged about MS for a while, so here goes...
I'm doing lots of work with mapping and webservices, and had (for simplicity) created a basic DTO object called LatLng, consisting of just a Latitude and Longitude property. Then I discovered that MS had an object GeoCoordinate (in System.Device.Location) that had LatLng and also a method for calculating distance to another LatLng. I already had that formula but thought I'd simplify my code by using the GeoCoordinate object and it's DistanceFrom function. Simple - pull out my LatLng class, replace with GeoCoordinate, all good. Everything worked from the start.
Until... I needed to access the LatLng data from a webservice, using JSON. The webservice ran fine, but JQuery wouldn't parse the JSON. Turns out that the GeoCoordinate object has some properties, defined as Double, that default to NaN - NOT zero! When the webservice serializes the object to JSON, it does it as {"Latitude" : NaN} which the browser can't parse as valid JSON, so the whole thing is unreadable. Those properties include Altitude, Speed, HorizontalAccuracy and VerticalAccuracy.
Now, I use the GeoCoordinate in so many places I don't want to explicitly set all these properties (which I don't even need anyway). So I subclassed GeoCoordinate, wrapping it in my own class and setting those four values to 0 in the constructor. All good, surely? Nope, still not working in the JSON serialisation. Close inspection showed that Altitude and Speed were now zero, but the accuracy properties still coming back as NaN. Checked the documentation, confirmed those properties are settable. Setting the value to 1 is all good, but setting it to 0 "works" (as in no error thrown) but the value remains as NaN.
Now, I sort-of understand why you can't have an accuracy of zero in this context... but WHY Microsoft, don't you either throw an exception or at least DOCUMENT that??? (The property even has a documented "Out of Range" exception, but they don't throw it for zero )
So two oddities - failing to parse the JSON because of an unquoted text literal "NaN", and a property with an undocumented un-settable value. Wasted the best part of the afternoon...
(And on the subject of rants, CodeProject seems to have lost the toolbar when making posts in a forum...)
|
|
|
|
|
DerekT-P wrote: GeoCoordinate object has some properties, defined as Double, that default to NaN - NOT zero! Can you tell me what would those values be for someone driving in Denmark at sealevel, at a stop sign while traveling due North?
|
|
|
|
|
More to the point, someone on the equator due south of Greenwich.
I was more taken aback that the serialiser generates non-parseable JSON from a "valid" GeoCoordinate object, tbh.
|
|
|
|
|
Yep,
I covered altitude, speed and heading. Realized after I posted that I should have used a city on the prime meridian for that extra kick.
DerekT-P wrote: I was more taken aback that the serialiser generates non-parseable JSON I think you might find that some people are surprised that you are trying to serialize an uninitialized object.
|
|
|
|
|
This is all documented in the docs for the GeoCoordinate class, which isn't serializable. The serialization/deserialization code needs to handle the NaNs to ensure uninitialized data is properly converted. Serializing a NaN to a number is not correct. NaN isn't an out of range error, it's simply not initialized. These are different concepts.
|
|
|
|
|
I can find a Microsoft document that does indeed state the constructor with no parameters creates an instance "with no fields set". The description of other constructors (e.g. passing lat/lng values) does not mention that other fields are not set. In this case, GeoCoordinate uses NaN to mean "unknown". I feel it would make more sense to use double? (i.e. nullable) values anyway - which would also be supported by JSON.
However my main gripe is not that the fields are NaN, but that ASP.Net fails to serialise NaN values in a way that makes the output JSON invalid. Valid input should not generate invalid output. I recognise (belatedly!) that NaN is itself not supported by JSON but that doesn't change the fact that valid input should generate valid output. If it's unable to do so it should throw an exception, surely?
My other gripe is that the Accuracy fields are documented as Double, yet they are clearly not a "true" Double. You can assign a valid double value to it (i.e. zero) and yet after the assignment the value remains NaN. This is not the normal behaviour of a Double and as such it would be really, really, really helpful if it were documented. You can set it successfully to .000000000000001 but not to zero. It makes you wonder if there are other values it can't have...? (Oh, and I tried setting it to a negative value, just to see what happens; and it crashed the IIS Application Pool. It's now showing as "Stopped" but won't accept Start! Guess that's it's way of telling me to go to bed... )
|
|
|
|
|
|
Here's link to Google Maps showing what you're asking to be the defaults:
Google Maps
|
|
|
|
|
Here's the source of those two properties[^]
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Microsoft's business model is to grind you down and break you, make you realize that hope is a luxury you can't afford and that any attempt at resistance is futile.
To err is human. Fortune favors the monsters.
|
|
|
|
|
...meet in the hallway.
One asks the other: Can't you sleep either?
|
|
|
|
|
Cuz they're corrupt? Or...?
|
|
|
|
|
Sorry but no, it is other: It is because they are unisex, bisexual, gay, straight, unknown, black, yellow, white, grey, thin, medium, heavy, male, female ... and lot others ...
|
|
|
|
|
Oh, got it!
|
|
|
|
|
It's OK for Portrait mode, but it looks odd in landscape to me - too much white space on the left and right.
Since I mostly run CP on my Portrait monitor, it's not a problem, but I'm unusual in having the choice, I think.
What do you guys think?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
The main menu is on the right side now, instead of the left. Other than that, nothing major to complain about.
My usual layout is "fixed" and that seems fine so far.
modified 21-Mar-22 15:41pm.
|
|
|
|
|
Slacker007 wrote: The main menu is on the right site now, instead of the left.
Oh that's interesting. I hadn't realized that - it looks unbalanced now. Menus should be on the left.
|
|
|
|
|
To my mind the left edge is the logical place for the forum tree.
|
|
|
|
|
Richard MacCutchan wrote: To my mind the left edge is the logical place for the forum tree.
YES!
|
|
|
|
|
Until a couple of weeks ago all colors were muddy and matte but after today both eyes have had Cataract surgery and the colors are so vivid and the whites so white, it's given me a whole new outlook on life.
The less you need, the more you have.
Even a blind squirrel gets a nut...occasionally.
JaxCoder.com
|
|
|
|
|
Glad to hear it! It's a truly wonderful surgery that.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
That it is, been waiting a long time for VA to finally do it.
The less you need, the more you have.
Even a blind squirrel gets a nut...occasionally.
JaxCoder.com
|
|
|
|
|
I know you love photography. I can't imagine the improvement the surgery has given your eyes in regards to photography and all that goes with that.
|
|
|
|
|
I just got my right eye done today so it's going to be a couple of weeks before I can get out with my camera but am really looking forward to it.
In the past everything was fuzzy and dull, with the lenses they installed and cataracts removed things should be more in focus and colorful. In the past I had to rely on the camera, which is not all bad it's a D850 but there's so much more I want to do with it.
The less you need, the more you have.
Even a blind squirrel gets a nut...occasionally.
JaxCoder.com
|
|
|
|