Comment On The Matryoshka Method

"At one end of the system," Steve A writes "we have a fairly simple HTML-form that displayed a handful of shipping-related fields. At that the other end, there's a database table that pretty much matches those fields one-to-one. But in the middle.... there's a lot more." [expand full text]
« PrevPage 1 | Page 2Next »

Re: The Matryoshka Method

2009-12-21 09:43 • by dsckeld
Well, to me it just looks as if the dll in question were called by some VBScript from an ASP page. What's wrong with that?

It might look a little unwieldy, but would you rather make 1 insert call and a lot of update calls or maybe pass an array of unchecked values down to the database level?

(I am fairly sure that objects (like real Objects) were out of the question at the time.)

(second attempt)

Re: The Matryoshka Method

2009-12-21 09:57 • by CGoetz (unregistered)
293869 in reply to 293868
This function definition looks so horrible, I believe I have eye cancer from looking at it.

As a member of the clean code movement here in germany, I can only strong advise a refactoring of this beast.

Or if it is a sealed dll:
Write an adaptor against it and use your own functions instead, this will make the code mich better on your side.

Re: The Matryoshka Method

2009-12-21 09:59 • by anonymouse (unregistered)
I have similar problems. Imagine the same kind of architecture... but written in the sloppiest spaghettiest PHP you've ever seen.. by the manager (we are not a software house, so the manager isn't/wasn't a programmer). That's what I get to maintain.

Re: The Matryoshka Method

2009-12-21 10:03 • by Spivonious (unregistered)
The code looks very enterprisey.

Re: The Matryoshka Method

2009-12-21 10:08 • by Shai (unregistered)
293872 in reply to 293868
dsckeld:


It might look a little unwieldy, but would you rather [...] pass an array of unchecked values down to the database level?



Unchecked, as opposed to all of them declared Variant?

Re: The Matryoshka Method

2009-12-21 10:19 • by frits (unregistered)
Stack overflow at line 0.

Re: The Matryoshka Method

2009-12-21 10:26 • by - (unregistered)
293874 in reply to 293871
Spivonious:
The code looks very enterprisey.


Why tie yourself to inflexible variable names? Why specify variant when that can be implied? 'Guru' coder also spots the pointless 'byVal' call on a reference type and eliminates this redundancy...

...So this is even more enterprisey:

Public Function InsertXMLShipment(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo) As Boolean


I'm sure you would agree this is a MUCH better approach

Re: The Matryoshka Method

2009-12-21 10:31 • by Harrow (unregistered)
293875 in reply to 293869
CGoetz:
...Write an adaptor against it and use your own functions instead, this will make the code mich better on your side.

Isn't that how the current architecture came into existence in the first place? As described, it sounds exactly like layer after layer of wrappers and adaptors written by a succession of developers each trying to make his own code mich better on his side.

-Harrow.

Re: The Matryoshka Method

2009-12-21 10:33 • by BlueKnot
fShpCarPieces As Variant
I remember that episode of M*A*S*H...

Re: The Matryoshka Method

2009-12-21 10:52 • by KattMan
The only problem with the "representative line" is the fact that they are all variants, strongly type them.

If you complain about the number of arguments, make a structure (oh VB6, make a Type) and simply pass a variable of that structure, there you go, one parameter that holds all those values.

Re: The Matryoshka Method

2009-12-21 10:56 • by Daniil (unregistered)
That looks about right. We got plenty of those kinds of methods written in both VB and Java. Debugging that and adding new things is just a delight. They should really teach that in schools. Its so easy to manage that kind of code.

Re: The Matryoshka Method

2009-12-21 10:59 • by Daniil (unregistered)
293880 in reply to 293874
Ha! +1 on this one. I'm bored.

Re: The Matryoshka Method

2009-12-21 11:03 • by frits (unregistered)
293881 in reply to 293878
KattMan:
The only problem with the "representative line" is the fact that they are all variants, strongly type them.

If you complain about the number of arguments, make a structure (oh VB6, make a Type) and simply pass a variable of that structure, there you go, one parameter that holds all those values.


So replace "Long Parameter List" code smell with a variation of the "Large Class" smell. Why not just declare a bunch of global variables and refactor with the "accumulate and fire" anti-pattern ?

Re: The Matryoshka Method

2009-12-21 11:08 • by Rodnas (unregistered)
It burns my eyes AND o my god, the humanity

Re: The Matryoshka Method

2009-12-21 11:20 • by Zylon
293885 in reply to 293881
frits:
So replace "Long Parameter List" code smell with a variation of the "Large Class" smell. Why not just declare a bunch of global variables and refactor with the "accumulate and fire" anti-pattern ?

Awww cute, someone just read that refactoring book.

Re: The Matryoshka Method

2009-12-21 11:27 • by Bim Job (unregistered)
293888 in reply to 293875
Harrow:
CGoetz:
...Write an adaptor against it and use your own functions instead, this will make the code mich better on your side.

Isn't that how the current architecture came into existence in the first place? As described, it sounds exactly like layer after layer of wrappers and adaptors written by a succession of developers each trying to make his own code mich better on his side.

-Harrow.
For some reason, this reminds me of the Last Goon Show of All:

Bluebottle: Eccles! Turn the knob on your side!
Eccles: I haven't got a knob on my side.

This ... thing ... is way beyond refactoring. It's like senile dementia from a junior programmer: open your mouth, and just start babbling whatever comes in to your head.

One thing bothers me, though: the function name. What on earth is InsertXMLShipment all about? Is it now a mandatory requirement for every enterprisey solution to include "XML" in the function name, as well as the architecture? Or has the company in question given up entirely on shipping actual physical items, and gone down the underpants ... XML ... profit route of shipping bags o' bytes instead?

Re: The Matryoshka Method

2009-12-21 11:29 • by cromar (unregistered)
That's no moon!

Re: The Matryoshka Method

2009-12-21 12:00 • by Anynomous Coward (unregistered)
/me wonders where the inputs are(n't?) sanitized at?

Re: The Matryoshka Method

2009-12-21 12:06 • by Mortal (unregistered)
Shipping-related fields... table with almost one-to-one equivalency... and somehow, somewhere, XML is inserted?

Re: The Matryoshka Method

2009-12-21 12:18 • by matthewr81
If I remember right, ASP (VB6 style) all variables are variants, so any VB6 interfaces have to define variable as variants.

That being said, passing a string of XML would be better, but the variants are not the WTF.

Re: The Matryoshka Method

2009-12-21 12:22 • by frits (unregistered)
293893 in reply to 293885
Zylon:
frits:
So replace "Long Parameter List" code smell with a variation of the "Large Class" smell. Why not just declare a bunch of global variables and refactor with the "accumulate and fire" anti-pattern ?

Awww cute, someone just read that refactoring book.


Awww cute, someone's sticking up for his pal.

Re: The Matryoshka Method

2009-12-21 12:24 • by Dwedit
The real Matryoshka Method is to stick everything inside an .MKV file.

Re: The Matryoshka Method

2009-12-21 12:30 • by Bim Job (unregistered)
293895 in reply to 293893
frits:
Zylon:
frits:
So replace "Long Parameter List" code smell with a variation of the "Large Class" smell. Why not just declare a bunch of global variables and refactor with the "accumulate and fire" anti-pattern ?

Awww cute, someone just read that refactoring book.


Awww cute, someone's sticking up for his pal.
Awww, cute, someone's decided to duck the issue via an ad hominem attack.

Only a god-damn lunatic would replace seventeen function parameters with global variables in the middle of DLL hell.

Refactoring is designed, if that is the word, to accommodate changes in specification and/or cleanups after the proverbial death march.

This "code" does not need refactoring. It cries out for replacing.

Re: The Matryoshka Method

2009-12-21 12:38 • by frits (unregistered)
293896 in reply to 293895
Bim Job:
frits:
Zylon:
frits:
So replace "Long Parameter List" code smell with a variation of the "Large Class" smell. Why not just declare a bunch of global variables and refactor with the "accumulate and fire" anti-pattern ?

Awww cute, someone just read that refactoring book.


Awww cute, someone's sticking up for his pal.
Awww, cute, someone's decided to duck the issue via an ad hominem attack.

Only a god-damn lunatic would replace seventeen function parameters with global variables in the middle of DLL hell.

Refactoring is designed, if that is the word, to accommodate changes in specification and/or cleanups after the proverbial death march.

This "code" does not need refactoring. It cries out for replacing.


Does your brain work properly? Do you think calling something an "anti-pattern" is an endorsement?

Bad code is bad.

Re: The Matryoshka Method

2009-12-21 12:54 • by LongCat (unregistered)
293897 in reply to 293896
frits:
Bim Job:
frits:
Zylon:
frits:
So replace "Long Parameter List" code smell with a variation of the "Large Class" smell. Why not just declare a bunch of global variables and refactor with the "accumulate and fire" anti-pattern ?

Awww cute, someone just read that refactoring book.


Awww cute, someone's sticking up for his pal.
Awww, cute, someone's decided to duck the issue via an ad hominem attack.

Only a god-damn lunatic would replace seventeen function parameters with global variables in the middle of DLL hell.

Refactoring is designed, if that is the word, to accommodate changes in specification and/or cleanups after the proverbial death march.

This "code" does not need refactoring. It cries out for replacing.


Does your brain work properly? Do you think calling something an "anti-pattern" is an endorsement?

Bad code is bad.


And Long Cat is Long!!

(sorry, couldn't resist....)

Re: The Matryoshka Method

2009-12-21 13:02 • by Bim Job (unregistered)
293898 in reply to 293896
frits:
Bim Job:
frits:
Zylon:
frits:
So replace "Long Parameter List" code smell with a variation of the "Large Class" smell. Why not just declare a bunch of global variables and refactor with the "accumulate and fire" anti-pattern ?

Awww cute, someone just read that refactoring book.


Awww cute, someone's sticking up for his pal.
Awww, cute, someone's decided to duck the issue via an ad hominem attack.


Does your brain work properly? Do you think calling something an "anti-pattern" is an endorsement?

Bad code is bad.
I'm sorry, I must have mistaken your comment (in bold) for some sort of offensive brain-damaged response to another poster.

My mistake. Given that assumption, it seems entirely reasonable to assume that you meant to endorse an "anti-pattern."

Re: The Matryoshka Method

2009-12-21 13:18 • by frits (unregistered)
293899 in reply to 293898
Way to cut out your diatribe about "global variables" and such. It is ironic that you accuse me of ad hominem attack, when that what provoked my "brain-damaged response" to antoher poster. Why do you care anyway? Troll much? Oh, and apology accepted.

Re: The Matryoshka Method

2009-12-21 13:24 • by hoodaticus (unregistered)
That is the ugliest function signature I have ever seen. It's infectiously ugly. Even without the article, you know its nastiness must have transmitted and promulgated itself throughout the surrounding system like a virus.

Dust off and nuke it from orbit. It's the only way to be sure.

Re: The Matryoshka Method

2009-12-21 13:29 • by hoodaticus (unregistered)
293902 in reply to 293873
frits:
Stack overflow at line 0.

Frits makes me laugh every time! Heaven forbid this monster be recursive...

Re: The Matryoshka Method

2009-12-21 13:36 • by hoodaticus (unregistered)
293903 in reply to 293878
KattMan:
The only problem with the "representative line" is the fact that they are all variants, strongly type them.

If you complain about the number of arguments, make a structure (oh VB6, make a Type) and simply pass a variable of that structure, there you go, one parameter that holds all those values.


VB6 has classes bra. The huge number of arguments is a giant cluebat that the coder was clueless.

Re: The Matryoshka Method

2009-12-21 13:52 • by Coyne

HTML
| ^
v |
???????
| ^
v |
XML
| ^
v |
SOAP
| ^
v |
??????
| ^
v |
VB6.EXE (service)
| ^
v |
VB6.DLL
| ^
v |
VB6.DLL
| ^
v |
Stored Procedure
| ^
v |
Stored Procedure
| ^
v |
More Stored Procedures
| ^
v |
SQL Insert
| ^
v |
Table



Gee...and then we wonder why we need EHz processors to see a cat jump in a box and fall over.

Re: The Matryoshka Method

2009-12-21 14:02 • by hoodaticus (unregistered)
LOL- with all those arguments, this "function" returns what for error information? A Boolean.

Re: The Matryoshka Method

2009-12-21 14:05 • by Tzimisce
Maybe the developers wanted to get "n-tier architecture" on their resumes.

Re: The Matryoshka Method

2009-12-21 14:25 • by hoodaticus (unregistered)
293911 in reply to 293907
With that handle, do you play Bloodlines?

Re: The Matryoshka Method

2009-12-21 14:29 • by coyo
293912 in reply to 293906
hoodaticus:
LOL- with all those arguments, this "function" returns what for error information? A Boolean.


Yeah, but how many different values can a microsoft boolean have? I know its more than two.

Re: The Matryoshka Method

2009-12-21 14:44 • by foxyshadis (unregistered)
293913 in reply to 293912
coyo:
hoodaticus:
LOL- with all those arguments, this "function" returns what for error information? A Boolean.


Yeah, but how many different values can a microsoft boolean have? I know its more than two.

A BOOL is just an int. But a VB Boolean is a real bool, there's no way to assign anything else to it without casting it to Variant.

Re: The Matryoshka Method

2009-12-21 14:56 • by Bacon Bits
293915 in reply to 293913
foxyshadis:
coyo:
hoodaticus:
LOL- with all those arguments, this "function" returns what for error information? A Boolean.


Yeah, but how many different values can a microsoft boolean have? I know its more than two.

A BOOL is just an int. But a VB Boolean is a real bool, there's no way to assign anything else to it without casting it to Variant.


Clearly the sane thing to do is to change the return value from Boolean to Variant.

Re: The Matryoshka Method

2009-12-21 15:09 • by Some Wonk (unregistered)
293917 in reply to 293897
LongCat:
frits:
Bim Job:
frits:
Zylon:
frits:
So replace "Long Parameter List" code smell with a variation of the "Large Class" smell. Why not just declare a bunch of global variables and refactor with the "accumulate and fire" anti-pattern ?

Awww cute, someone just read that refactoring book.


Awww cute, someone's sticking up for his pal.
Awww, cute, someone's decided to duck the issue via an ad hominem attack.

Only a god-damn lunatic would replace seventeen function parameters with global variables in the middle of DLL hell.

Refactoring is designed, if that is the word, to accommodate changes in specification and/or cleanups after the proverbial death march.

This "code" does not need refactoring. It cries out for replacing.


Does your brain work properly? Do you think calling something an "anti-pattern" is an endorsement?

Bad code is bad.


And Long Cat is Long!!

(sorry, couldn't resist....)


And Leon is getting larger...

Re: The Matryoshka Method

2009-12-21 15:14 • by Richard (unregistered)
So, was anyone tempted to click the "Hear a Blog" link for more comic relief?

Re: The Matryoshka Method

2009-12-21 15:29 • by Shriike (unregistered)
I'm just curious. I had a similar problem to tackle, and I don't think my solution was really any better. (I passed in an array of strings for the variables, and an array of strings for names of variables). While I'm aware this probably isn't an ideal solution. I do wonder, what is?

Someone suggested building a class, but that seems kind of dumb to me, the constructor would be just as unwieldy and each attribute would have to be referenced individually, so surely there is a better solution to this, right?

Captcha: nisl, I think it's like a missile?

Re: The Matryoshka Method

2009-12-21 16:23 • by Katana (unregistered)
293921 in reply to 293919
Shriike:

Someone suggested building a class, but that seems kind of dumb to me, the constructor would be just as unwieldy and each attribute would have to be referenced individually, so surely there is a better solution to this, right?


Yes, but in VB you could make it very clear as in
dim x as new XMLShipment()
WITH x
.Property1="whatever"
.SomeOtherBit = "dude"
.FileNotFound = IsBooleanTrue(false)
END WITH

and it would be very clear to someone who later had to read the code what you were stuffing all those values into, as opposed to just having 40 lines of code setting values that have no obvious relationship to one another.

Re: The Matryoshka Method

2009-12-21 16:35 • by iToad (unregistered)
293922 in reply to 293902
hoodaticus:
frits:
Stack overflow at line 0.

Frits makes me laugh every time! Heaven forbid this monster be recursive...


Some people thought that the LHC was going to generate some sort of mini black hole which would destroy the earth. If you called this thing recursively, it could actually happen.

Re: The Matryoshka Method

2009-12-21 17:04 • by BCS (unregistered)
I think I spotted a typo; the "pmen" in the function name should be removed.

Re: The Matryoshka Method

2009-12-21 17:12 • by SomeCoder (unregistered)
293925 in reply to 293917
Some Wonk:

And Leon is getting larger...


WIN. This comment is just full of WIN.

Re: The Matryoshka Method

2009-12-21 18:05 • by hoodaticus (unregistered)
293926 in reply to 293919
Shriike:
I'm just curious. I had a similar problem to tackle, and I don't think my solution was really any better. (I passed in an array of strings for the variables, and an array of strings for names of variables). While I'm aware this probably isn't an ideal solution. I do wonder, what is?

Someone suggested building a class, but that seems kind of dumb to me, the constructor would be just as unwieldy and each attribute would have to be referenced individually, so surely there is a better solution to this, right?

Captcha: nisl, I think it's like a missile?


I'm not sure what you're trying to do, but it sounds perfectly okay to me, although you may want to research the Collection object, using one array for the "names of variables" / keys and a Collection object to store the data itself. This will let you retrieve data by string key without having to array scan the variable names yourself with every access. There are advantages and disadvantages to using VB Collections that I won't go into, and the solution you already have is likely to be optimum if there are fewer than, say, a hundred variables in the array to scan.

What the OP's WTFer did - storing the raw data on the stack as a huge number of arguments to a function - is a WTF. The whole thing comes crashing down if you run out of stack space. And what happens if he has to add new data to insert/update? Oh well, re-write the function! Using a few classes would let the system be much more flexible than this trainwreck. If the OP's WTFer was using OOP all along, then he never would have amassed 17 arguments in a function... his solution would have tended towards much more elegance.

It sounds like you are passing two array references and maybe a couple other arguments into a function. Without knowing what your problem is, the way you are doing it now sounds perfect and by no means a WTF.

Re: The Matryoshka Method

2009-12-21 18:07 • by hoodaticus (unregistered)
293928 in reply to 293915
Bacon Bits:
Clearly the sane thing to do is to change the return value from Boolean to Variant.


ZOMG LOL!

Re: The Matryoshka Method

2009-12-21 18:25 • by Quirkafleeg (unregistered)
293929 in reply to 293919
Shriike:
Captcha: nisl, I think it's like a missile?
Only if you've poked one of its ‘I’s out.

Re: The Matryoshka Method

2009-12-21 19:00 • by Coyne
293932 in reply to 293907
Tzimisce:
Maybe the developers wanted to get "n-tier architecture" on their resumes.


Hey, can I get an n-tier architecture on my resume with this?


static boolean equal(int a, int b)
{
int tiers = 100;
int tier_a[] = new int[tiers];
int tier_b[] = new int[tiers];
boolean tier_r[] = new boolean[tiers];
tiers--;

tier_a[0] = a;
tier_b[0] = b;

for (int j = 0; j < tiers; j++)
{
tier_a[j+1] = tier_a[j];
tier_b[j+1] = tier_b[j];
}

tier_r[tiers] = (tier_a[tiers] == tier_b[tiers]);

for (int j = tiers; j > 0; j--)
{
tier_r[j-1] = tier_r[j];
}

return tier_r[0];
}



"My tiers are deeper than your tiers!"


Addendum (2009-12-21 19:06):
Sorry, after writing this, the old "Ken-L Ration" ditty popped into my head and I just had to...

"My tiers are deeper than your tiers."
"My tiers are deeper than yours!"
"My tiers are deepest 'cause they've got SOAP in them!"
"My tiers are deeper than yours!"

Re: The Matryoshka Method

2009-12-21 19:12 • by lolwtf
One of the few articles that actually made me ask WTF out loud.

Re: The Matryoshka Method

2009-12-21 19:30 • by Hot Shot (unregistered)
293935 in reply to 293929
My eye!
« PrevPage 1 | Page 2Next »

Add Comment