Archive for the ‘Hello World!’ Category

WTF (2)

Friday, August 14th, 2009

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…

WTF (1)

Wednesday, July 29th, 2009

Let me start by pointing out that VisualBasic is not my cup of tea. I don’t like all those implicit castings. Like this:

[sourcecode language='vb']Function DecimalSeparator() As String
DecimalSeparator = (1 / 2).ToString.Substring(1, 1)
End Function[/sourcecode]

The .Net way of doing things is of course:

[sourcecode language='vb']Function DecimalSeparator() As String
Return System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator
End Function[/sourcecode]

But I guess that was too much for this programmer.