WTF (2)

While reviewing some code for a project of our company I found this:

[code=c#]public override void Redirect(PipelineContext pipelineContext)
{
string linkcp = “”;
if (linkcp == null || linkcp == “” || linkcp.Length == 0)
linkcp = “default.aspx”;

pipelineContext.Response.Redirect(linkcp);
}[/code]

It first drew my attention because of the if-statement (testing a string being not null or string.Empty three times) and its missing brackets. But it surprised – well, shocked – me because the variable that was assigned, and validated afterwords directly. The writer of this piece of WTF declared that it was generated, and needed some custom implementation…

I couldn’t help, but think why not – in that case – do it this way:

[code=c#]public override void Redirect(PipelineContext pipelineContext)
{
string linkcp = string.Empty;
// TODO: implement logic.
if (string.IsNullOrEmpty(linkcp))
{
linkcp = “~/default.aspx”;
}
pipelineContext.Response.Redirect(linkcp);
}[/code]

or, if should fail while not implemented yet

[code=c#]public override void Redirect(PipelineContext pipelineContext)
{
public override void Redirect(PipelineContext pipelineContext)
{
throw new NotImplementedException(“TODO: implement logic.”);
//string linkcp = string.Empty;
//if (string.IsNullOrEmpty(linkcp))
//{
// linkcp = “~/default.aspx”;
//}
//pipelineContext.Response.Redirect(linkcp);
}
}[/code]

What is it about writing comments that my fellow developers seems to dislike that much? It would make reading and understanding code so much easier…

Leave a Reply

You must be logged in to post a comment.