Another Priceless WTF

Published Sat, Dec 11 2004 18:18 | William

I've seen some really bad code - but this takes the cake .

Friend ReadOnly Property CheckUserRole() As Boolean 
  Get
    Dim user As SystemUser = SystemUser.CurrentUser
    If user.AssertRole(RoleTypes.Admin) Then
      Return 0
    Else
      If user.AssertRole(RoleTypes.Training) Then
       Return 1
      Else
        If user.AssertRole(RoleTypes.Supervisor) Then
          Return 2
        End If
      End If
    End If
  End Get
End Property

There's no GD excuse from trash like this.  NONE.  VB.NET - (Option Strict On) = VB6  .  Why even write in .NET without Option Strict On?  As soon as the guy that wrote this cashed his paycheck he should have been arrested for THEFT.

But the money quote is this:

<<Isn't it incredible how many run-time mysteries become compile-time wavy underlines with circles and arrows and flashing lights and sound effects when you use Option Explicit/Option Strict?
>>

Filed under: ,

Comments

# William said on December 12, 2004 9:54 PM:

Terrible and ignominious code!

It shows a dull disinterest in the possibility that now and in the future, assertRole can return True for User AND Admin AND Training or indeed any one of eight combinations. I do not know whether it can but certainly in Windows 2000, group and role membership is flexible.

Whether or not the possibility exists, the code could have been written to work flawlessly in EITHER scenario but it is characteristic of dull fellows to want to write code only for a specific narrow scenario.

In fact, the code is of negative net worth, for it poses as a "tool" giving you "simple" access to flags, like a Russian bureaucrat out of Gogol who has appointed himself in charge of all village affairs and proceeds to make a drunken mess of them, or the clowns in Shanghai who impounded my author copies last June and demanded 200 Yuan to release them.

We got rid of thug Communism only to have shadowy bureaucracies lurk in code.

# William said on December 12, 2004 11:40 PM:

You know what's really scary. I believe a boolean returns 0 if it's unnasigned in VB doesn't it? Well if they don't have one of those three privileges then it will return 0 and 0 is what they define as admin so all non-defined groups get to run as admin. Hurray everybodies admin! What a stroke of pure genious. I guess the concept of bit flags never occured to this guy so now he has to recode every time a permission is added.

# William said on December 12, 2004 11:42 PM:

But the money qoute says it all. If you get a bunch of squiggly lines and warnings, the OBVSIOUS VB6 answer is "Option Strict Off"

Search

This Blog

Tags

Community

Archives

News

My other sites

Cool Stuff

Book Stuff

Security

ORM

Data Access

Funny Stuff

Compact Framework Stuff

Web Casts

My KnowledgeBase Articles

My MVP Profile

Design Patterns

Performance

Debugging

Remoting

My Fellow Authors

My Books

LINQ

Misc

Speech

Syndication

Email Notifications