12.11.2012

KISS & AJAX Deletes

I run across this type of code often (ASP.Net MVC)

[HttpPost]
public string Delete(ObjectId id)
{
    var record = _Database.Get<Record>(id);
    if (record == null)
    {
        return "No matching record!";
    }
    _Database.Remove<Record>(id);
    return "Deleted record!";
}

If the user is interested in deleting the record, does it matter if someone else beat them to it?

[HttpPost]
public string Delete(ObjectId id)
{
    _Database.Remove<Record>(id);
    return "Deleted record!";
}

Isn't the HTTP 200 OK status code enough to indicate success, the user or the software knows the context of the request it made:

[HttpPost]
public void Delete(ObjectId id)
{
    _Database.Remove<Record>(id);
}

Simple things to think about when reviewing code for simplicity, one line of code is much easier to maintain than seven.





comments powered by Disqus