Comment On The FOR-CASE paradigm

Marc Holmes sent in a code snippet that explores a whole new programming paradigm using CASE statements and FOR loops ... [expand full text]
« PrevPage 1Next »

re: The FOR-CASE paradigm

2004-07-01 14:03 • by cooper
Maybe Im not getting a joke here, but hy not just iterate over the 5 objects rather than have a conditional?

re: The FOR-CASE paradigm

2004-07-01 14:39 • by Steele Price
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.

re: The FOR-CASE paradigm

2004-07-01 15:07 • by cooper

>>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.

re: The FOR-CASE paradigm

2004-07-01 15:17 • by fogelman
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.

RE: The FOR-CASE paradigm

2004-07-01 15:21 • by ben.lovell@bbc.co.uk (Ben Lovell)
What Marc didnt tell you is that that was his code ;) Only kiddin Marc

re: The FOR-CASE paradigm

2004-07-01 15:41 • by Marc Holmes
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!

re: The FOR-CASE paradigm

2004-07-02 12:48 • by cablito
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

re: The FOR-CASE paradigm

2004-07-04 13:56 • by Jim
Isn't it wonderful when people are measued by the number lines of code that they have produced.

re: The FOR-CASE paradigm

2004-07-07 23:30 • by @
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.

re: The FOR-CASE paradigm

2004-07-08 17:30 • by Kiliman
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

re: The FOR-CASE paradigm

2004-09-03 15:45 • by xeron
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.

re: The FOR-CASE paradigm

2004-10-14 19:26 • by Anonymous
Demosceners.

Re: re: The FOR-CASE paradigm

2006-05-03 09:12 • by VB Syntax
70976 in reply to 22581
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?"

Re: The FOR-CASE paradigm

2006-05-03 10:10 • by 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.

Re: The FOR-CASE paradigm

2006-05-03 14:14 • by GoatCheez
71006 in reply to 70982
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....

Re: re: The FOR-CASE paradigm

2006-05-03 14:47 • by aikimark
71009 in reply to 22582

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

Re: The FOR-CASE paradigm

2007-12-14 09:36 • by B (unregistered)
166921 in reply to 70982
Azkoyen:
Still though, I'd love to come upon a situation that requires a breakless select in a for loop.&nbsp; That'd be cool.

Do you think Duff's Device satisfies your conditions?

Re: re: The FOR-CASE paradigm

2007-12-16 17:28 • by Peter B. (unregistered)
167094 in reply to 22582
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.

Re: The FOR-CASE paradigm

2007-12-16 18:11 • by ExistentialWTF (unregistered)
Maybe the six objects are written by six developers who bitterly refuse to acknowledge a common ancestor.

VB needs ducktaping.

Re: re: The FOR-CASE paradigm

2007-12-17 07:00 • by EoN (unregistered)
167130 in reply to 167094
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.

Re: re: The FOR-CASE paradigm

2007-12-18 10:18 • by randomscener (unregistered)
167328 in reply to 22583
xeron, wtf really? :D

Re: The FOR-CASE paradigm

2008-01-06 21:55 • by 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.

Re: re: The FOR-CASE paradigm

2008-02-04 03:16 • by @ (unregistered)
174850 in reply to 70976
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.

Re: The FOR-CASE paradigm

2010-03-22 03:57 • by LD (unregistered)
This just makes me want to cry.

Supra Shoes

2010-06-19 03:08 • by 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.


Re: Supra Shoes

2010-10-13 12:02 • by Spearhavoc! (unregistered)
324907 in reply to 312290
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?!

Re: re: The FOR-CASE paradigm

2011-06-15 21:00 • by CrushU (unregistered)
350177 in reply to 22582
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]);
}

Re: The FOR-CASE paradigm

2012-01-03 07:50 • by jay (unregistered)
oh good you got this far, now turn it into a state pattern.

:o)
« PrevPage 1Next »

Add Comment