• Prakash (unregistered)

    burn this fellow, and banish from programming.

  • JD (unregistered)

    Ah, I see! He listed 23 before 21! What an idiot!

  • Anderson (unregistered)


    This hurts my brain.


    I'm ususally not a fan of commenting code because most of the time the code speaks for itself but MY LORD- what is this doing?

  • Mike (unregistered)

    See, it says 'Start'. That's where it's starting.

    :/

  • G Dawg (unregistered)

    Yet more proof that VB programmers should be seriously forced into a career change. I hear that 'crash test dummy' is a nice field to be in.

  • T Man (unregistered)

    Yes G Dawg, 'cause one idiot wrote this VB snippet then all VB coders are idiots. With that logic you should be forced into a career change.

  • Matthew W. Jackson (unregistered)

    Total WTF.

    Seriously, even if you don't know what this does, you should still refactor it a bit more. I'm feeling a bit helpful today, so I'll go ahead and tack a whack at it.

    For one, there at most only needs to be one call to Val(Left(sFormNumber, 2)) and one to Val(Left(sFormNumber, 3)), although I suspect both of those could be combined if I knew more about the input data.

    iFirst2 = Val(Left(sFormNumber, 2))
    iFirst3 = Val(Left(sFormNumber, 3))

    Select Case iFirst2
    Case 10,11,12,17,43,46 '...so on...
    DoSomething()
    End Select

    Select Case iFirst3
    Case 186,187,188,191,192 '...so on...
    DoSomething()
    End Select

    It would still be a big WTF, but it would be much more readable and maintainable (not to mention a LOT more efficient....repeated calls to Left are going to give your garbage collector a heart attack!!!!)

  • Jim Bolla (unregistered)

    Yikes. Well if you assigned Val(Left(sFormNumber, 2)) and Val(Left(sFormNumber, 2)) to variables before the IF statement, this code could be a lot shorter. after that i'd put all these magic numbers into an array and loop through the comparisons. then you could short circuit the evaulation so it can stop after the match. that's if i couldn't refactor out the need for these magic numbers altogether.

  • Simon (unregistered)

    Hungarian Notation is a WTF of its own, Matthew. ;-)

  • Simon (unregistered)

    Anyway, since when is VB6 code garbage collected?

  • Jeff S (unregistered)

    The question isn't turning this more efficient by changing it to a case or grouping form's together or whatnot; it's very similiar to a database exercise.

    Clearly these forms or whatever sFormNumber refers to need a few more attributes stored with them to classify them properly. Then, spaghetti code like the above simply becomes:

    SELECT CASE sFormClass
    CASE 'Admin' : DoSomething()
    CASE 'User' : DoSomethingElse()
    CASE 'Testing' : DoOneOtherThing()
    END SELECT

    and that's it. And if you do it properly, it becomes much more readable and expandable as well.

    Sometimes storing an extra attribute here and there -- much like adding an extra column or two to entities in your database -- can turn hundreds and hundreds of lines of code or crazy WHERE clauses into something very short, efficient and self-explainatory.

  • BradC (unregistered)

    Ah, we can even improve on Matthew Jackson's improvement:

    iFirst2 = Val(Left(sFormNumber, 2))
    iFirst3 = Val(Left(sFormNumber, 3))

    Select Case iFirst2
    Case 10 to 15, 17, 43, 46, 71 to 79 '...so on...
    DoSomething()
    End Select

  • Bustaz Kool (unregistered)

    I have always thought that languages should have an IN comparison operator. e.g.,

    FormNumber2 = Val(Left(sFormNumber, 2))

    if FormNumber2 IN (10,11,12,17,43,46 '...so on...

    I like Matthew W. Jackson's solution (with magic numbers defined, of course) and Jeff S, as always, has an interesting point to make.

  • Ed Kaim (unregistered)

    Whoever owns this code now might want to fix "Val(Left(sFormNumber, 2)) = 260" before the missles launch.

  • WanFactory (unregistered)

    who wants to bet on whether some of those ORs really ought to be ANDs? Though there's probably no way to know for sure...

  • Jesper Holmberg (unregistered)

    It took a minute, but now I get it - he forgot 809. What a clown!

  • TownDrunk (unregistered)

    "Anyway, since when is VB6 code garbage collected? "

    When it's converted to VB.Net, as stated above...

  • Darren (unregistered)

    Bustaz: Pascal (and other languages, e.g. shell script, Ruby) agree with you.

    http://www.irietools.com/iriepascal/progref335.html

  • James Curran (unregistered)

    Simon:
    >> Anyway, since when is VB6 code garbage collected?

    Microsoft Basics have been garbage collecting space used for strings since at least TRS-80 Level II Basic, circa 1978.

    Jeff S:
    >> these forms or whatever sFormNumber refers to need a few more attributes stored with them to classify them properly.

    I think you're getting ahead of things here. It appears the sFormNumber is a value entered in a dialog, and we are now attempting to validate if the user typed in a good value.


  • Simon (unregistered)

    Delphi already does have an 'in' operator: http://www.prestwood.com/community/delphi/info/lessons/sets.html

  • Jeff S (unregistered)

    James -- it doesn't matter where FormNumber comes from. if it refers to SOMETHING, then that something should have an attribute on it that indicates what action to take or what is allowed or what should be done next.

    for example:

    set f = MyFormCollection(sFormNumber)
    select case f.formClass
    case ...
    case ...
    ....
    end select

    Too many programmers concentrate on optimizing the code itself, as opposed to optimizing the application or database model. In the short run it may seem not worth it, but the long run is what counts.

  • scott (unregistered)

    @wanfactory: Yeah, there's a way to be sure those shoulnd't be ANDs. A number can't have the first two digits of 11 and the first 3 digits of 813.

  • Guayo (unregistered)

    A WTF no less, but I wonder what those numbers mean, it seems to be a complex numerical series, you know, perhaps the coder isn't a very good programmer but a mathematical genius.

  • aspnetman (unregistered)

    I recognise this code!! It's my random error generator!!

  • Derick Bailey (unregistered)

    Wow, what a great bunch of comments! You guys rock...

    FYI - the sFormNumber is a group of numbers from a specific portion of a masked text box. The actual numbers represent a Form number, and the entire purpose of the validation was to ensure that the user had typed in a valid form number, and then to determine what validation to use on that form number.

    and to make things even more complicated... if you look at the numbers listed, you'll never ever ever find a 2 digit number that is the first 2 digits of a three digit number. In otherwords, you cannot have a form number "11" and a form number "117".

    I ended up with a solution very much like what Matthew W. Jackson suggested, just because I needed to get it done quickly.

    There were a total of 3 sections of code like this... this one was by far the largest and worst, though, which is why it got sent in. :)

  • CrashC (unregistered)

    When programmers think like this... I guess were lucky theres only 2 If then statements.

    They could have copied and pasted the whole If-Then...EndIF statement 60+ times.

  • Ben (unregistered)

    did anyone catch that
    Val(Left(sFormNumber, 2))
    will supercede
    Val(Left(sFormNumber, 3)), so anything in that first group will run? e.g.
    100, 101, 102, 103, 104 etc.?

  • Guayo (unregistered)

    @Ben
    I didn't catch it, Derick Bailey already explained. This is a bigger WTF to me. This seems to be like those russian dolls that inside contains another doll which contains another an so on. Change the dolls with WTFs and make those inner WTFs bigger and you will have this little piece of code.

  • Matt K (unregistered)

    >>> Yet more proof that VB programmers should be seriously forced into a career change. I hear that 'crash test dummy' is a nice field to be in.

    The problem is that VB is so easy to use that any idiot can program in it (and many do). Any idiot can swing a hammer, but it takes someone with skill to build a house that won't fall down. Maybe if they make VB harder and more cryptic (i.e. like writing in C/C++ for a Windows App), the idiots won't get far enough to even create a windows message box.

  • WanFactory (unregistered)

    I suppose a HashSet of valid values would endanger job-security by being both easy to maintain and efficient at runtime?

  • DarkBunny (unregistered)

    This is why I use Java. Stupid people have a harder time figuring it out. My problem when programming always seems to go like this: "Oops, I left that feature out, where can I put it?" inserts feature randomly in the data structure, modifies existing code to fit

  • KoFFiE (unregistered)

    @WanFactory: Hash-sets can hardly be called "efficient at runtime" imho... A case-structure will be the fastest, or if performance would really be needed, and the array of accepted would be really really big, put the numbers in an sorted constant array, and apply a binary search...

    @Matt K: you hit the sweet spot about VB coders, it's not that they all are stupid, it's that the majority is stupid, and they stick with VB, cause it's simple and easy - but they will never ever write a brilliant piece of code, unless a terrible accident happens :p An average VB-coder has no clue what is done behind his back, and just uses everything as if it's magic... Don't ask em to write any of those basic functions themselfs, cause then you get answers like "is that possible?" I once asked this to someone to create a window on the fly, in pure code and got this reply... How ignorant and stupid some ppl are is really amazing...

  • (cs)

    After seeing all of these WTFs, I have often thought that I am a programming Genius [6]

  • (cs)

    OK after a lot of staring I see what the problem is: it is a performance issue! The If statement should be broken down into nested If statements since the Or in VB6 doesn't work like the OrElse in .NET... Am I right or am I right?

  • (cs) in reply to Simon

    That's not hungarian notation.  I don't know what it is, but iFirst2 isn't an index into anything.

     

  • (cs) in reply to Bustaz Kool

    I have always thought that languages should have an IN comparison operator.

    If you can't add one trivially, just switch languages. In most OO langauges the collections classes will already let you do IN quite easily, but it would be no trouble to add.

    In fact, I think that the more syntax your language has, the less powerful it is. My real test is whether you have syntax for IF. A good language shouldn't need this. Smalltalk doesn't.

  • (cs) in reply to Simon
    :
    Hungarian Notation is a WTF of its own, Matthew. ;-)


    Of course, I never personally advocate using Hungarian Notation, but I do tend to use whatever style is currently in use when working with other people's code.

    Inconsistent coding styles bother me more than any style which differs from my own.

    (This is Matthew, by the way...had to register for the new forums and I certainly didn't want to type in my full name to log in).
  • (cs)

    I think I will add this to the "CodeBook" one day there will be a complete book of WTF!  It will rule the world....


    ASPotato.

  • (cs)

    <font face="Arial" size="2">Why're you using a screenshot of the code? I mean, even the simpler code editors with syntax highlighting (thus) support exporting as (HT|X)ML.

    By the way, this board has the most gratuitously ornate posting form I have ever seen. Whatever happened to formatting [tag]s? We are programmers, after all.
    </font>

  • (unregistered) in reply to Ed Kaim
    :
    Whoever owns this code now might want to fix "Val(Left(sFormNumber, 2)) = 260" before the missles launch.


    OMFG!
    The tears are streaming down my face. I can't type this. I am laughing too hard.

    Thank you <g>
  • (unregistered) in reply to Bustaz Kool
    <font size="3">I have always thought that languages should have an IN comparison operator.</font>

    xBase has the INLIST operator:

    IF INLIST(FormNumber2, 10, 11, 12, 17, 43, 46...)

    Garrett Fitzgerald
    http://blog.donnael.com/
  • (unregistered)

    Anyone wondered what this s**t is actually for?

  • MichaelDok (unregistered)

    I recently tried Organic Body Essentials https://organicbodyessentials.com/products/organic-face-cream and was pleasantly surprised. Their CBD grease provided swift relief fit my angst without any clear side effects. The flavor was merciful and not overpowering. Additionally, their purchaser navy was tiptop, addressing my queries promptly. Entire, I effectively recommend Organic Body Essentials CBD fit anyone seeking high-quality CBD products.

Leave a comment on “When If-Then Attacks”

Log In or post as a guest

Replying to comment #:

« Return to Article