• Sole Purpose Of Visit (unregistered)

    Well, it would have helped if they'd used FIrstOrDefault and surfaced the bug immediately, wouldn't it?

    Sometimes a foolish consistency is the hobgoblin of little minds. Sometimes a lack of consistency is just asking for it.

  • (nodebb)

    Bet $$ that the assignments were added after, and there was not a unit test for the null result...

  • dpm (unregistered)

    I can't think of any excuse for treating a single instance of a class as a list, which is what irritates me the most about this code. The only reason would be massive copypasting, but that would be above-and-beyond-the-usual amount of stupid.

  • (nodebb)

    Actually, Dapper has a terrible mechanism for fetching additional properties, be it many to one or one to many. It's only useful for simple objects with primitive type properties. Still, the solution is either use Dapper's bad API, or use another approach (a different ORM or direct ADO.NET), not run multiple queries.

  • (nodebb) in reply to dpm

    Yes the naming here is atrocious. Singular and plural both went out the window of a Hong Kong skyscraper.

  • Prime Mover (unregistered)

    "a foolish consistency is the hobgoblin of little minds" the most overused and misapplied blethering stupidity that has ever been applied to the software development industry.

    I've had it quacked at me far too often by colleagues and other animals. It's usually in response to an observation that code would be far easier to read and understand if it were only set down on the page neatly. Make the stuff line up, fill in the docs, use standard English spellings for comments and not your made-up phonetic-intuitive illiteracy, etc. etc. And most of all, if you devise a more-or-less functional and efficient technique for achieving an effect, use it over and over again, rather than re-inventing it differently three times on the same page.

    Grr. Rant over.

  • dpm (unregistered) in reply to Mr. TA

    It's not the naming, it's the actual use of .ToList() and .First() and [0], all of which are completely unnecessary.

  • (nodebb)

    Not familiar with .net or Dapper, but would "vendorlist[0].Id" not be equal to "id"?

  • Sole Purpose Of Visit (unregistered) in reply to dpm

    Well, here's a good reason. (Obviously unrelated to the OP.)

    If you, say, condition all outputs from an external API (in this case Dapper) to be IEnumerable<Vendor>, then you're automatically preparing all the following Linq code to behave (mostly) as though you were using FP. Which is pretty much what Linq is for.

    After that, you can just model your mapping as:

    if (vendors.Any()
    {
        var frist = vendors.First();
        // Possibly add frist to mapping.
    
        foreach (var vendor in vendors.Skip(1);
        {
            // Map it somehow
        }
    }
    else
        // Return empty mapping
    

    Recursion optional, and probably not advised in C#. But this is essentially car:cdr from FP. A strong argument for it is that it's pretty much future-proof -- any changes that come before are automatically list processed with no additional side effects and no surprises such as new exceptions.

  • (nodebb) in reply to Sole Purpose Of Visit

    "Foolish" is the operative word. In software development, it seems like being consistent is rarely a foolish decision.

  • (nodebb) in reply to Sole Purpose Of Visit

    "Frist" is German for Deadline.

  • DQ (unregistered) in reply to R3D3

    Damn, I thought you were joking, but it is actually true :)

  • Chris (unregistered) in reply to Prime Mover

    Sounds like some confusion on their part between DRY principles + consistent formatting versus "bEcAuSe We'Ve AlWaYs DoNe It ThAt WaY" attitudes. Establish coding standards isn't foolish. Refusing to revisit them when a better idea is put forward or circumstances change (e.g. adopted a new language or technology) is foolish.

  • theodinspire (unregistered) in reply to nerd4sale

    Yes, yes it would be.

  • Downright Ugly (unregistered)

    So much .... audacious ugliness in such a short amount of code. It's hard to look away. It's so ugly, it's created a new reason for Rated R. No alibi...

  • PotatoEngineer (unregistered)

    I usually quote it as "any consistency at all is the hobgoblin of small minds" right after someone points out how inconsistent I am.

    But then, I usually make jokes at my own expense.

Leave a comment on “Magical Thinking”

Log In or post as a guest

Replying to comment #:

« Return to Article