A bit of source code – The Daily WTF

FreeBSDGuy sends us a VB .Net snippet that overlays a series of errors:

If (gLang = "en") Then
    If (item.Text.Equals("Original")) Then
        item.Enabled = False
    End If
ElseIf (gLang = "fr") Then
    If (item.Text.Equals("Originale")) Then
        item.Enabled = False
    End If
Else
    If (item.Text.Equals("Original")) Then
        item.Enabled = False
    End If
End If

The goal of this code is to disable the “original” field, so that it cannot be edited by the user. To do this, it checks which language the application is configured to use, and then checks for the word “Original” in English or French based on the language.

The first obvious mistake is to identify UI widgets based on the text inside them, rather than some actual identifier.

As an aside, this text sure sounds like to mark which already doesn’t allow editing, so I think they’re using the wrong widget here, but I can’t be sure.

Then we hardcode our comparison string, which isn’t great anyway, but then we hardcode two Languages. It’s worth noting that .NET has some pretty robust internationalization features to help you externalize those strings. I guess this app has a lot going for it if (gLang = "en") calls scattered around, rather than the frame for it being worn.

But there is another problem that this code does not clarify: they are using multiple unique identifiers to find this widget, so they don’t actually have to work If (item.Text.Equals("Original")) check. FreeBSDGuy replaced this entire block with a single line:

 item.Enabled = False

[Advertisement]

BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Find out how!

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *