Just Beastly

by in Error'd on

Not to be outdone by Michael R., another prolific participant styles himself The Beast In Black. A handful of his experiences follow here. [psst. Mr Black. Check out this explanation of a half-closed interval)

Buyer Beast bemoans "I knew that the global situation was bad, but when Amazon starts offering disdiscounts (or discountcounts, perhaps?) you know that the world is truly up the toilet without a paddle roll."


Extended Models

by in CodeSOD on

If I'm being completely honest, I'm mildly anti-ORM. I'm not about to go on a rampage and suggest they should absolutely, never, ever, ever be used, but I think they tend to create a lot of problems. Instead of being a true mapping between our object model and our relational model, they're their own tool, with its own idosynchracies, and a lot of "magic" that conceals its actual operation. For simple applications, they're great, but once you start getting into something more complicated than basic CRUD operations, you're in for a world of hurt. And that's before someone makes a mistake with eager vs. lazy fetching.

Today's anonymous submission offers us a good example of another way the mismatch can go wrong between objects and relations.


Mostly In One Line

by in Coded Smorgasbord on

Today's a day for a smorgasbord. We're going to start with a classic kind of bad code, from astephens:

pbUpdates.Value = int.Parse(Math.Truncate(percentage).ToString());

All the Cases Covered

by in CodeSOD on

David's application has loads of unit tests. Many of the unit tests even go so far as to exhaustively test every combination of parameters. So seeing something like this is pretty common:

[Test]
[TestCase(false, false, false, false, false)]
[TestCase(false, false, false, false, true)]
[TestCase(false, false, false, true, false)]
[TestCase(false, false, false, true, true)]
[TestCase(false, false, true, false, false)]
[TestCase(false, false, true, false, true)]
[TestCase(false, false, true, true, false)]
[TestCase(false, false, true, true, true)]
[TestCase(false, true, false, false, false)]
[TestCase(false, true, false, false, true)]
[TestCase(false, true, false, true, false)]
[TestCase(false, true, false, true, true)]
[TestCase(false, true, true, false, false)]
[TestCase(false, true, true, false, true)]
[TestCase(false, true, true, true, false)]
[TestCase(false, true, true, true, true)]
[TestCase(true, false, false, false, false)]
[TestCase(true, false, false, false, true)]
[TestCase(true, false, false, true, false)]
[TestCase(true, false, false, true, true)]
[TestCase(true, false, true, false, false)]
[TestCase(true, false, true, false, true)]
[TestCase(true, false, true, true, false)]
[TestCase(true, false, true, true, true)]
[TestCase(true, true, false, false, false)]
[TestCase(true, true, false, false, true)]
[TestCase(true, true, false, true, false)]
[TestCase(true, true, false, true, true)]
[TestCase(true, true, true, false, false)]
[TestCase(true, true, true, false, true)]
[TestCase(true, true, true, true, false)]
[TestCase(true, true, true, true, true)]
public void UpdateClientSettingsTest(bool canCreateBeneficiary, 
	bool canCreatePayment, bool canCreateDeal, 
	bool canEditPlan, bool isPayrollEnabled) 
{

}

Actively Xing Out

by in CodeSOD on

Today, I'm honestly not sure that the WTF is in the code we're looking at. Jeff needed to support an older PHP application which used client side JavaScript heavily. This block was copy-pasted many times throughout the code base:

var ajaxRequest;  // The variable that makes Ajax possible!
       
try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
} catch (e){
    // Internet Explorer Browsers
    try{
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try{           
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e){
            try{
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP.4.0");
            }
            catch(e){
                // Something went wrong
                echo("Something Wrong. Please try again later!");
                return false;
            }
        }
    }
}

All Michael

by in Error'd on

One of our most dedicated readers, Michael R., is also one of our most dedicated contributors, sometimes sending us several submissions in a single day. We haven't featured all of them, but now we're making up for that. Today, it's wall-to-wall Michael, mostly food misadventures. Michael might tell you we've cooked the plot, but he can't prove it.

On leaving France (it's a long story), Michael was confused at the airport. "Yo Sushi at Charles de Gaulle Terminal, please make up your mind about what payment types you accept." I think this one is pretty clear; just because a sign says they accept one form of payment it doesn't mean they categorically reject all others. So if your card is on either sign, you're covered. I hope he got fed.


Broken Loop

by in CodeSOD on

Kyle sends us a puzzler of bad code today. It appears in a "JSP-like" codebase- which Kyle provides no futher details on, but certainly hints at a serious WTF underpinning this code.

boolean loop = true;
while (loop) {
    // fake loop to break out of
    loop = false;
    doesStuff();
	moreStuff();
	etc();
}

Gonna Need an Extension

by in CodeSOD on

Ever since the DOS days, determining file type based on the three letter extension in its filename has been a common practice. I'd argue that it's not a good practice, but it's become so standard that it's hard to avoid. It's so common that pretty much any language in wide use has some sort of "get extension" method. C# is no exception.

Of course, having a convenient and commonly used helper method is no barrier to writing it yourself, and Andrew found this code in their application, which is meant to extract "png", or "jpg" as the extension.


Archives