• (nodebb)

    It might be enterprisey, but:

    • It offers such opportunities for control coupling. (Ref: Constantine and Yourdon)
    • The parameter that selects which value to return is, essentially, meaningless at the point of call.
  • Quite (unregistered)

    isLatitude true or false?

    No no no, what you got to do is write an Enum whose values are CoordinateType.Latitude and CoordinateType.Longude, and load it from an XML file (in case you want to expand the technique to use e.g. generalised Cartesian coordinates, or perhaps include time as a further coordinate so as to measure times of travel, etc. etc.

  • akozakie (unregistered)

    Obviously solutinos get absorbed by dense brain matter, emitting negative enterprisons and gluons W, T and F.

  • TheCPUWizard (unregistered)

    If that is the only use-case then, yes WTF.... but there are plenty of use-cases where they type of method can be appropriate. Much more of the codebase would be needed to declare this a WTF.

    [However the use of a Boolean rather than an enum IS a WTF, at a minimum for readability and also for extensibility]

  • G (unregistered) in reply to Quite

    public enum IsLatitude { true, false, locationNotFound }

  • Ron Fox (google) in reply to akozakie

    Yeah I was gonna say TRWTF was not running a spell check on the article text.

  • bvs23bkv33 (unregistered)

    if we have solutinos its too late for spell check, we need spill check

  • A_L (unregistered)

    Spill check or spell chick?

  • Code Golfer (unregistered)

    An additional parameter to select? How wasteful.

    Make the method stateful, and return latitude or longitude on alternate calls. Eliminates a wasted parameter, simplifies the code, and only requires a little discipline to always call the method twice in the same order. Bob's your well-ordered uncle!

  • me (unregistered)

    Why not just return both the lat and lon with one call? 99% of the time you probably want both.

  • gleemonk (unregistered) in reply to me

    Your solution is alright I think, but I like Code Golfer's solution better.

  • OldCoder (unregistered)

    Am I missing something? The first time this is run it will return the first point that matches the required latitude; the second time it will return the first point with the required longitude.

    Those points are unlikely to belong to the same location unless the dataset is very small. These functions are useless. If you need X and Y then both X and Y have to be part of the key.

  • (nodebb) in reply to Quite

    As boring as I am, I thought of altitude first.

    But now it's too late - the code is already written, and rewriting a function is un-enterprisey. Unlike expanding a function.

    public static decimal? GetPosition(string endpointId, ICollection<UserGeoPositionModel> userGeoPositions, bool isLatitude, bool isLongitude, bool isAltitude, bool isTime, bool isMultiverseIndex)

    Or we'd do it right and expand the definition of bool:

    enum Bool { True, False, FileNotFound , IsLongitude , IsLatitude , Maybe , IsAltitude , IsAltitudeOrDepth, FristPost };

    Addendum 2016-08-17 10:41: I miss the preview and easy formatting ...

    Addendum 2016-08-17 10:43: And now that the comment design is toatlly fucked up:

    My Italian is a bit rusty - what is a solutino?

  • (nodebb)

    "CPU time is cheap. Programmer time is expensive. "

    Software is like a car: it has to be cheap when you buy it. Who would ever be so paranoid to have a look at maintenance cost and TCO before it's broken.

  • Anon (unregistered)

    Did anyone else notice that the endPointId.Contains(x.UserID) is actually broken?

    If you pass in endPointID = 1000 then userID = 1, 10, 100, 1000 would all be true...

  • Yazeran (unregistered) in reply to gleemonk

    Yep mee too. Much more potential foe evilness by burying a call somewhere in a (seldom) used function and wait for the fireworks. :smiling_imp:

  • Paul Neumann (unregistered) in reply to Anon

    If you pass in endPointID = 1000 then userID = 1, 10, 100, 1000 would all be true..

    Iff endPointID instanceof string && x.UserID instanceof string, then true. Iff endPointID instanceof IEnumerable<typeof(x.UserID)>, than it is checking if the value ofx.UserID` is a member of that enumeration.

    So, at the end of the day, you have to ask yourself -- Do you want to partial match your endPointID, or do you want multiple endPointIDs for your Point?

  • dudeNumber4 (unregistered) in reply to akozakie

    Solutinos are Italian solutions.

  • Roger Chaplin (google) in reply to Code Golfer

    I just threw up in my mouth a little bit.

  • dev (unregistered)

    var point = userGeoPositions.Where(x => x.userId = userId);

    um, no, you couldn't write like that, it wouldn't even compile.........

  • Jack (unregistered)

    This isn't so much a WTF as it is a minor headscratcher. Yes, there's a better way, but this way is pretty OK. It's not like we're looking at an ERE or a hardcoded mess of spaghetti code here.

  • Jeremy Hannon (google)

    The original example is simpler, but it two does two passes over the collection for the userId. Why? Because LINQ expressions are not fully evaluated until after they are actually need. Actually, the original example would not actually work for multiple reasons, especially since lines 2 and 3 are trying to read a property and at this point the value point would be an IQueryable(Of T), or similar depending on the LINQ provider that userGeoPositions actually is.

    Yes, there are OTHER ways to write that code, but none that I can think of that are any cleaner.

  • epsalon (unregistered)

    What language is this with => and ? and decimal?

  • (nodebb) in reply to epsalon

    Swift#?

  • Cody (unregistered) in reply to epsalon

    C#

  • Jeremy Hannon (google) in reply to aapis

    C#. If you (or anyone else reading this) were wondering => is a lambda expression, ? is a ternary operator, and decimal? indicates a nullable decimal. In C# adding ? to the end of any value-typed object (basically primitives) makes a nullable version of that type.

  • Derf Skren (unregistered)

    You know what else works to reduce the LOC? Not using a property where a public member will do.

  • PaulMuurayCbr (unregistered)

    Well, obviously the two calls to get the latitude and longitude will be right after one another, so this function should cache the object in a static variable and check there first. If there are N threads typically running, it might make sense to have the cache contain N items.

    Genius!

  • (nodebb)

    solutino n. a computer programming implementation solution that saves at least one line of source code per use; especially when the solutino is insaneo or idiotico

  • Falco20019 (unregistered) in reply to dev

    Yeah, first he should compare instead of assign and second, he really should use First or FirstOrDefault instead of Where if he wants to use properties (or has he really defined the properties as extension for his enumerable...?)

  • (nodebb)

    IMO the WTF starts with having two separate variables for longitude and latitude.

  • Richard (unregistered) in reply to dev

    Indeed. It should be:

    var point = userGeoPositions.First(x => x.userId == userId);

    Also, the example of calling the GetPosition method wouldn't work - you can't assign a Nullable<decimal> to a decimal.

  • Chris (unregistered) in reply to Derf Skren

    Unless you want public access to read the value, but only private access to write it. Or you can make it read-only so that it can only be written by the constructor if it is never meant to change once initialised.

  • Jeremy Hannon (google) in reply to Falco20019

    Defining Latitude and Longitude extension properties of an enumerable... wow! That would a WTF!

  • Jeremy Hannon (google) in reply to Derf Skren

    "You know what else works to reduce the LOC? Not using a property where a public member will do."

    First, there are several very good reasons for generally using properties and not public members. You may also be forced to do so by your toolset (data binding in XAML GUIs, for example).

    Secondly, it doesn't save any LOCs in C# because that language has auto properties that create the code and handle the backing variable in one line (C# 3.0 and up), so declaring a property is a single LOC (by my count anyway):

    public decimal longitude { get; set; }

  • Hernâni Oliveira (unregistered)

    Why not improve the solution? I think this is far better.

    public static void GetPosition(string endpointId, ICollection<UserGeoPositionModel> userGeoPositions, out decimal? latitude, out decimal? longitude) { var position = userGeoPositions.FirstOrDefault(x => endpointId == x.UserID); if (position == null) { latitude = null; longitude = null; return; } latitude = Convert.ToDecimal(position.latitude); longitude = Convert.ToDecimal(position.longitude); }

    Usage:

    decimal? lat; decimal? lon;

    GetPosition(endpointId, geoPositions, out lat, out lon);

    // At this point we have both values in just one search...

  • Jax (unregistered)

    Or return a tuple or an object with the lat and the lon.

Leave a comment on “Location Not Found”

Log In or post as a guest

Replying to comment #:

« Return to Article