Nothing is True

by in CodeSOD on

Alexander sends us this snippet, where we change our definition of truth to something which eschews concrete definitions and accepts that existence is ephemeral. Truth and false are just illusions we project onto a reality that is itself just an illusion. In the end, we are all nothing.

    public enum Bit
    {
        None = -1,
        False = 0,
        True = 1
    }

Sdrawkcab Error Handling

by in CodeSOD on

When interacting with RESTful web services, there's a depressingly common anti-pattern: always return status 200 OK, but embed a more meaningful status code in the body of the response. Frequently, the embedded status code is just the HTTP status code you should have returned in the first place.

This "fixes" situations where you have badly behaving clients that don't do proper error handling, but also breaks the entire point of doing REST.


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.


Archives