• cooper (unregistered)

    Maybe Im not getting a joke here, but hy not just iterate over the 5 objects rather than have a conditional?

  • Steele Price (unregistered)

    Exactly, you only need 1 line in the Case Statements, then use a WITH block below it.

    Some people just don't think in terms of objects... The even bigger question is do all these classes inherit from a common base class?

    VB Needs a refactoring tool that shows new coders how to do refactoring, most VB programmers don't even know what refactoring is.

    It would be really nice to see how people CORRECT the mistakes found in this site in the most efficient way.

    It's great to laugh at the "most rediculous item of the day" but it would even be more interesting for coders starting out to be able to see these fairly common mistakes and learn how to avoid/correct them in highly efficient ways.

  • cooper (unregistered)


    >>Some people just don't think in terms of objects... The even bigger question is do all these classes inherit from a common base class?

    That's what I was thinking, was maybe there was some non-inherit reason you couldn't do that in VB, and had to ref the properties directly.

  • fogelman (unregistered)

    I love it.
    And then you can also re-use Icnt and acheive object re-use. No byte left behind!

    It would be interesting to see if the scrubbing/ comparison of the same aleged address field for each case uses the same loop construct with favoring fixed Icnt #..

    But stuffing arrays with each field from the record returned by the 6 different sources really gets under my skin. If one wanted a bloated copy of the data fetched they should just create a SOAP object.

  • ben.lovell@bbc.co.uk (Ben Lovell) (unregistered)

    What Marc didnt tell you is that that was his code ;) Only kiddin Marc

  • Marc Holmes (unregistered)

    Thanks Ben, as if my 'reputation' is not bad enough.

    I have no idea what this guy was thinking, but then you should see his UI :p

    I suppose he needed the CASE statement otherwise he'd have ended up running each piece of code 5 times, right? ;) Wait a minute... D'Oh!

  • cablito (unregistered)

    this will never beat of the now former programmer who was able to code such a complex subroutine, with so many nested Ifs (he did not know about elseif or iif) all within a loop (scannind data records storing them in undeclared variables).

    It was so intense VB took exceptionally long to compile his project.

    Best of all his subroutine started with

    ON Error Resume Next

  • Jim (unregistered)

    Isn't it wonderful when people are measued by the number lines of code that they have produced.

  • @ (unregistered)

    You will be happy to know that this programming style isn't restricted to Basic, isn't restricted to Windows, and isn't restricted to programs running in user mode. Some Linux device drivers aren't even coded by volunteers, some are coded by professionals who work for the device makers. And yet the device works. It's astounding.

    What's in a name, in C we have to call it the select-case paradigm, but it still smells the same. What about the name of the product, or me? Sorry, I don't want to be fired.

  • Kiliman (unregistered)

    This is how I would have done it (in C#). Note: I'm making an assumption that these are all instances of the same class (based on the identical properties and methods).

    // create array to hold list of items
    SomeClass[] items = new SomeClass[] { ManObj, RETObj, DISObj, AGYObj, LAWObj, LiAgObj };

    // loop through items
    for (int i = 0; i < items.Length; i++)
    {
    // get item from array and then call methods, properties, etc.
    SomeClass obj = items[i];
    obj.GetRecords(CaseNumber, ConnObj);
    TxtKeyContact[i] = obj.KeyContact;
    TxtAddName[i] = obj.Name;
    TxtTelephone[i] = obj.Fax;
    .
    .
    .
    }

    Simple loop without any messy if or switch-case statements. And if they need to work with a new object, they simply add it to the array.

    Kiliman

  • xeron (unregistered)

    There is a group of programmers who code in ASM, and write the most efficient code... at a 2600 meeting someone brought a 15-20 minute graphical presentation on a floppy and ran it on a laptop (years ago)... it was pretty impressive. If anyone knows the name of these programmers or has a link to the presentation I'd like to see it again.

  • Anonymous (unregistered)

    Demosceners.

  • VB Syntax (unregistered) in reply to @
    Anonymous:
    You will be happy to know that this programming style isn't restricted to Basic, isn't restricted to Windows, and isn't restricted to programs running in user mode. Some Linux device drivers aren't even coded by volunteers, some are coded by professionals who work for the device makers. And yet the device works. It's astounding.

    What's in a name, in C we have to call it the select-case paradigm, but it still smells the same. What about the name of the product, or me? Sorry, I don't want to be fired.

    select-case? You're fired! In C, i'd call this construct a for-switch. Language-agnostically, I'd probably call it a loop-switch. How about iterative switch? A "switcheration?"

  • Azkoyen (cs)

    I don't know whatever language that's written in, but shouldn't there be some sort of a 'break' statement at the end of each case block?  If there IS a break statement in that language, and it's missing, then it means the code above results in the following execution:

    START
    first pass, exec all blocks starting from 0
    second pass, exec all blocks starting from 1
    third pass, exec all blocks starting from 2
    fourth pass, exec all blocks starting from 3
    fifth pass, exec all blocks starting from 4
    sixth pass, exec last block only (5)
    END

    If the language does need a break line, then the code in those blocks are getting executed mutiple times, and it's an even worse WTF.

    Still though, I'd love to come upon a situation that requires a breakless select in a for loop.  That'd be cool.

  • GoatCheez (cs) in reply to Azkoyen
    Azkoyen:
    I don't know whatever language that's written in, but shouldn't there be some sort of a 'break' statement at the end of each case block?  If there IS a break statement in that language, and it's missing, then it means the code above results in the following execution:

    START
    first pass, exec all blocks starting from 0
    second pass, exec all blocks starting from 1
    third pass, exec all blocks starting from 2
    fourth pass, exec all blocks starting from 3
    fifth pass, exec all blocks starting from 4
    sixth pass, exec last block only (5)
    END

    If the language does need a break line, then the code in those blocks are getting executed mutiple times, and it's an even worse WTF.

    Still though, I'd love to come upon a situation that requires a breakless select in a for loop.  That'd be cool.


    Unless they intended to do it that way in the first place! I doubt they did tho lol....
  • aikimark (cs) in reply to Kiliman

    Anonymous:

    Simple loop without any messy if or switch-case statements. And if they need to work with a new object, they simply add it to the array.

    Kiliman

    With the "txt" prefix of the assignment statements, I suspect that the data is going to an array of textbox controls on a form.  As such, we can't really apply the easy fix of converting these separate txt_____ arrays into a single array of user-defined datatypes or objects.  If that were the case, then only one assignment statement would be required.

    This is a VB WTF code example, so Kilman's suggestion would most likely look a little like this:

    Dim objThing As Object
    For Icnt = 0 to 5
    Select Case Icnt
    Case 0
    ManObj.GetRecords ...
    set objThing = ManObj
    Case 1
    RETObj.GetRecords ...
    set objThing =  RETObj
    Case 2
    DISObj.GetRecords ...
    set objThing = DISObj
    Case 3
    AGYObj.GetRecords ...
    set objThing = AGYObj
    Case 4
    LAWObj.GetRecords ...
    set objThing = LAWObj
    Case 5
    LiAgObj.GetRecords ...
    set objThing = LiAgObj
    End Select
    txt_____(Icnt) =  objThing.______
    txt_____(Icnt) =  objThing.______
    txt_____(Icnt) =  objThing.______
    Next
  • B (unregistered) in reply to Azkoyen
    Azkoyen:
    Still though, I'd love to come upon a situation that requires a breakless select in a for loop.  That'd be cool.
    Do you think Duff's Device satisfies your conditions?
  • Peter B. (unregistered) in reply to Kiliman

    I feel like being pedantic, so I'm going to say that it would be better to do your for block like this:

    for (int i = 0, int j = items.Length; i < j; i++)

    That way is a lot faster if you have to do it on a large list.

  • ExistentialWTF (unregistered)

    Maybe the six objects are written by six developers who bitterly refuse to acknowledge a common ancestor.

    VB needs ducktaping.

  • EoN (unregistered) in reply to Peter B.
    Peter B.:
    I feel like being pedantic, so I'm going to say that it would be better to do your for block like this:

    for (int i = 0, int j = items.Length; i < j; i++)

    That way is a lot faster if you have to do it on a large list.

    Thank god someone pointed this out. Everyone else who posted anything before this should hop on-board the failboat. YOU FAIL.

  • randomscener (unregistered) in reply to xeron

    xeron, wtf really? :D

  • zzo38 (unregistered)

    I think there are 2 mistakes:

    (1) The programmer doesn't understand object-oriented programming.

    (2) The programmer is stupid, why is the FOR and CASE in there anyways?

    Probably better is:

    oA = Array(ManObj,RETObj,DISObj,AGYObj,LAWObj,LiAgObj)

    Hopefully this way will work (although I don't know because I haven't tested it) However, this is late binding.

    Also, I think they should use tabstrips instead of like they do now.

  • @ (unregistered) in reply to VB Syntax
    VB Syntax:
    @:
    You will be happy to know that this programming style isn't restricted to Basic, isn't restricted to Windows, and isn't restricted to programs running in user mode. Some Linux device drivers aren't even coded by volunteers, some are coded by professionals who work for the device makers. And yet the device works. It's astounding.

    What's in a name, in C we have to call it the select-case paradigm, but it still smells the same. What about the name of the product, or me? Sorry, I don't want to be fired.

    select-case? You're fired! In C, i'd call this construct a for-switch. Language-agnostically, I'd probably call it a loop-switch. How about iterative switch? A "switcheration?"
    You're right, I don't know what I was thinking. In C it's a for-case, the same as in VB. This was in a device driver from a hardware maker, running in kernel mode in Linux. The code was unbelievable, and yet it worked.

  • LD (unregistered)

    This just makes me want to cry.

  • oksupra.com (unregistered)

    Supra shoes are so popular all over the world. Whatever you take on Supra being in the Supra Skytop Shoes market. Now Supra Strapped Shoes also very popular attention. It is nice that they actually took the time to make Supra Skate Shoes that work well. Supra shoes is a brand that has been inspired, designed and marketed by passionate individuals. We have brought to you the fullest selection of Supra footwear at cheapest price. Overload Skateshop carries a wide range of Supra Shoes to fit your 9-stair kickflips.

  • Spearhavoc! (unregistered) in reply to oksupra.com
    oksupra.com:
    Supra shoes are so popular all over the world. Whatever you take on Supra being in the Supra Skytop Shoes market. Now Supra Strapped Shoes also very popular attention. It is nice that they actually took the time to make Supra Skate Shoes that work well. Supra shoes is a brand that has been inspired, designed and marketed by passionate individuals. We have brought to you the fullest selection of Supra footwear at cheapest price. Overload Skateshop carries a wide range of Supra Shoes to fit your 9-stair kickflips.

    I had no idea.

    Wait, a bot? HOW DID YOU GET PAST THE CAPTCHA?!

  • CrushU (unregistered) in reply to Kiliman

    One better;

    // loop through items for (int i = 0; i < items.Length; i++) { // get item from array and then call methods, properties, etc. doStuffOnItem(items[i]); }

  • jay (unregistered)

    oh good you got this far, now turn it into a state pattern.

    :o)

Leave a comment on “The FOR-CASE paradigm”

Log In or post as a guest

Replying to comment #:

« Return to Article